15 $pks = self::getPks ( $model );
16 return function ($index, $instance) use ($pks) {
18 foreach ( $pks as $pk ) {
19 $getter =
"get" . ucfirst ( $pk );
20 if (method_exists ( $instance, $getter )) {
21 $values [] = $instance->{$getter} ();
24 return implode (
"_", $values );
28 public static function search($model,$search,$fields,$initialCondition=
"1=1"){
29 $words=preg_split(
"@(\s*?(\(|\)|\|\||\&\&)\s*?)@", $search);
30 $words=array_filter($words,
'strlen');
32 foreach ($words as $word){
37 $condition=str_replace(
"||",
" OR ", $condition);
38 $condition=str_replace(
"&&",
" AND ", $condition);
39 $condition=
'('.$condition.
') AND ('.$initialCondition.
')';
43 public static function update($instance,$values,$updateManyToOneInForm=
true,$updateManyToManyInForm=
false) {
45 $className=\get_class($instance);
48 foreach ( $fieldTypes as $property => $type ) {
49 if ($type ==
"tinyint(1)") {
50 if (isset($values[$property])) {
58 foreach ( $relations as $member ) {
59 if ($updateManyToOneInForm) {
62 $fkClass=$joinColumn[
"className"];
63 $fkField=$joinColumn[
"name"];
64 if (isset($values[$fkField])) {
65 $fkObject=
DAO::getOne($fkClass, $values[
"$fkField"]);
71 if (isset($instance)) {
72 if ($instance->_new) {
81 if ($updateManyToManyInForm) {
83 foreach ( $relations as $member ) {
85 $newField=$member .
"Ids";
86 $fkClass=$annot[
"targetEntity"];
87 $fkObjects=
DAO::getAll($fkClass, self::getMultiWhere($values[$newField], $className));
99 private static function getPks($model) {
100 $instance=
new $model();
106 $ids=explode(
",", $ids);
107 if (
sizeof($ids) < 1)
110 $idCount=\sizeof($ids);
111 for($i=0; $i < $idCount; $i++) {
112 $strs[]=$pk .
"='" . $ids[$i] .
"'";
114 return implode(
" OR ", $strs);
121 $fkClass=$annot[
"className"];
124 $fkClass=$annot[
"targetEntity"];
127 if (isset($objectFK))
128 $fkClass=\get_class($objectFK);
132 $result[$member]=compact(
"objectFK",
"fkClass",
"fkTable");
140 foreach ( $relations as $member ) {
141 $fkInstance=self::getFkIntance($instance, $model, $member);
142 if(
sizeof($fkInstance)>0){
143 $result=array_merge($result,$fkInstance);
static getFieldsInRelations($class)
static getSearchWhere($fields, $value, $jokerBefore="%", $jokerAfter="%")
static getOne($className, $keyValues, $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an instance of $className from the database, from $keyvalues values of the primary key...
static getAnnotationInfoMember($class, $keyAnnotation, $member)
static setValuesToObject($object, $values=null)
Affects member to member the values of the associative array $values to the members of the object $ob...
static setMemberValue($instance, $member, $value)
static insertOrUpdateManyToMany($instance, $member)
Updates the $member member of $instance annotated by a ManyToMany.
static getFirstKey($class)
static getManyToMany($instance, $member, $array=null, $useCache=NULL)
Assigns / loads the child records in the $member member of $instance.
static getMultiWhere($ids, $class)
static getAll($className, $condition='', $loadManyToOne=true, $loadOneToMany=false, $useCache=NULL)
Returns an array of $className objects from the database.
static getFkIntance($instance, $model, $member)
static getIdentifierFunction($model)
static getMemberValue($instance, $member)
static getFieldTypes($className)
static getManyToManyFields($class)
static getFKIntances($instance, $model)
static getTableName($class)
static getOneToMany($instance, $member, $useCache=NULL, $annot=null)
Assign / load the child records in the $member member of $instance.
static getManyToOneFields($class)
static search($model, $search, $fields, $initialCondition="1=1")
static getKeyFields($instance)
static replaceFirstOccurrence($pattern, $replacement, $subject)
static update($instance, $values, $updateManyToOneInForm=true, $updateManyToManyInForm=false)
static update($instance, $updateMany=false)
Updates an existing $instance in the database.
static insert($instance, $insertMany=false)
Inserts a new instance $ instance into the database.