示例#1
0
 function build($resultSet)
 {
     $class_name = $this->__class__;
     $temp_result = array();
     $old_ids = array();
     $collid = 0;
     if ($resultSet) {
         $resultSet->beforeFirst();
         while ($resultSet->next()) {
             $collection_id = $resultSet->getData($this->__table__ . ".id");
             $collection_identity = $collection_id !== false;
             $collid = $collection_identity ? $collection_id : $collid;
             if (array_key_exists($collid, $temp_result) === false || !$collection_identity) {
                 $sameNameCounter = 1;
                 $newInstance = new $class_name();
                 $newInstance->buildFromResultset($resultSet);
                 $old_ids[$collid] = array();
                 foreach ($this->__belongs_to__ as $key => $value) {
                     $className = is_numeric($key) ? $value : $key;
                     $obj_name = strToLower($className);
                     $resolver = "";
                     $options = is_numeric($key) ? array() : Options::parse($value);
                     $tableas = array_key_exists("as", $options) ? $options["as"] : false;
                     $field = array_key_exists("field", $options) ? $options["field"] : strToLower($className);
                     if ($obj_name == strToLower($this->__class__)) {
                         $resolver = $sameNameCounter;
                         $sameNameCounter++;
                     }
                     if ($tableas) {
                         $newInstance->{$field} = new $className();
                         $newInstance->{$field}->buildFromResultset($resultSet, $tableas);
                     } else {
                         if (class_exists($className)) {
                             $newInstance->{$obj_name} = new $className();
                             $newInstance->{$obj_name}->buildFromResultset($resultSet, $newInstance->{$obj_name}->__table__ . $resolver);
                         } else {
                             trigger_error("Can't load Class [{$className}]", E_USER_WARNING);
                         }
                     }
                 }
                 foreach ($this->__has_one__ as $key => $value) {
                     $className = is_numeric($key) ? $value : $key;
                     $obj_name = strToLower($className);
                     $resolver = "";
                     if ($obj_name == strToLower($this->__class__)) {
                         $resolver = $sameNameCounter;
                         $sameNameCounter++;
                     }
                     $newInstance->{$obj_name} = new $className();
                     $newInstance->{$obj_name}->buildFromResultset($resultSet, $resolver);
                 }
                 foreach ($this->__has_many__ as $key => $value) {
                     $property_name = is_numeric($key) ? strToLower($value . "s") : strToLower($key . "s");
                     $newInstance->{$property_name} = array();
                     $old_ids[$collid][$property_name] = array();
                 }
                 $temp_result[$collid] = $newInstance;
             }
             $new =& $temp_result[$collection_id];
             foreach ($this->__has_many__ as $key => $value) {
                 $property_name = is_numeric($key) ? strToLower($value . "s") : strToLower($key . "s");
                 $class = is_numeric($key) ? $value : $key;
                 $temp_obj = new $class();
                 $table = $temp_obj->__table__;
                 $id = $resultSet->getData($table . ".id");
                 if (array_search($id, $old_ids[$collection_id][$property_name]) === FALSE || $id == NULL) {
                     $created = $temp_obj->buildFromResultset($resultSet);
                     if ($created) {
                         array_push($new->{$property_name}, $temp_obj);
                         array_push($old_ids[$collection_id][$property_name], $id);
                     }
                 }
             }
             if (!$collection_identity) {
                 $collid++;
             }
         }
     }
     $result = array();
     foreach ($temp_result as $model) {
         array_push($result, $model);
     }
     if ($this->__processFound__ && $resultSet != NULL) {
         $result["founds"] = $resultSet->getTotal();
     }
     return $result;
 }
示例#2
0
 function search($page = 1, $searchQuery = null, $sort = "id")
 {
     $m = $this->model;
     $temp = new $m();
     $searchQueryParsed = Options::parse($searchQuery);
     $where = array();
     $queryData = new stdClass();
     foreach ($searchQueryParsed as $key => $value) {
         if (APP_USE_LANGUAGE) {
             if ($value != "" && $value != null) {
                 if (isset($m->{$key})) {
                     $where[] = $temp->__table__ . ".{$key} LIKE \"%{$value}%\"";
                 } else {
                     $where[] = $temp->__table__ . ".{$key}_{$this->application->language} LIKE \"%{$value}%\"";
                 }
             }
         } else {
             if ($value != "" && $value != null) {
                 $where[] = $temp->__table__ . ".{$key} LIKE \"%{$value}%\"";
             }
         }
         $queryData->{$key} = $value;
     }
     $query = array();
     //if($this->order!=null) $query["order"] = $this->order;
     if ($sort != null) {
         $query["order"] = "{$temp->__table__}.{$sort}";
     }
     $query["group"] = $temp->__table__ . ".id";
     $query["limit"] = ($page - 1) * $this->perPage . "," . $this->perPage;
     $query["founds"] = true;
     if (count($where) > 0) {
         $query["where"] = implode(" AND ", $where);
     }
     /*
     if($condition!=null){
     	$query["where"] = $condition;
     }
     */
     $this->data["objects"] = Collection::load($this->model, $query, $total);
     $order = new stdClass();
     foreach ($this->orderFields as $key) {
         $order->{$key} = $key;
         $sym = $key . "symbol";
         $order->{$sym} = "[asc]";
         if ($key == $sort) {
             $order->{$key} .= " desc";
             $order->{$sym} = "[desc]";
         }
     }
     $this->data["order"] = $order;
     import("data.Pager");
     $page = max($page, 1);
     unset($this->data["objects"]["founds"]);
     $pager = new Pager($total, $this->perPage);
     $pager->to = "{$this->controller}/search/{page}/{$searchQuery}";
     $this->data["pager"] = $pager->build($page);
     $this->data["querydata"] = $queryData;
     $this->data["uri"] = linkForm("/{$this->controller}/search/{$page}/{$searchQuery}");
     $this->setView("{$this->folder}/{$this->subView}", $this->data);
 }
示例#3
0
 function button($content, $data, $attributes)
 {
     if (array_key_exists("type", $attributes)) {
         $type = $attributes["type"];
     } else {
         if (array_key_exists("to", $attributes)) {
             $type = "to";
             $to = TemplateLogic::content($attributes["to"], $data);
         } else {
             $type = "submit";
         }
     }
     $result = "";
     $name = TemplateLogic::content($attributes["name"], $data);
     $options = Options::parse($attributes["options"]);
     if (array_key_exists("action", $attributes)) {
         $options["action"] = $attributes["action"];
     }
     switch (strToLower($type)) {
         case "back":
             $result = buttonBack($name, $options);
             break;
         case "action":
             $result = buttonAction($name, $options);
             break;
         case "to":
             $result = buttonTo($name, $to, $options);
             break;
         case "reset":
             $result = buttonReset($name);
             break;
         case "submit":
         default:
             $result = submit_tag($name, $options);
             break;
     }
     return $result;
 }
示例#4
0
 function ulist($content, $attributes)
 {
     //global $app;
     $defaultValues = trim($content) == "";
     $name = $attributes["name"];
     $field = array_key_exists("label", $attributes) ? $this->process($attributes["label"]) : "name";
     $selected = array_key_exists("selected", $attributes) ? $this->process($attributes["selected"]) : NULL;
     $result = "";
     $options = Options::parse($attributes["options"]);
     if (array_key_exists("values", $attributes)) {
         $values = explode(";", $attributes["values"]);
         foreach ($values as $value) {
             $data = explode(":", $value);
             $liData = array("id" => $data[0]);
             if ($item->id == $selected) {
                 $liData["class"] = "active";
             }
             $liContent = strtolower($options["addlinks"]) == "true" ? link_tag($data[1], "#") : $data[1];
             $result .= simple_tag("li", $liContent, $liData);
         }
     }
     if (array_key_exists("collection", $attributes)) {
         if ($defaultValues) {
             $collection = $this->data->get($attributes["collection"]);
             if (is_array($collection)) {
                 foreach ($collection as $item) {
                     //$field = (isset($item->name)) ? "name" : "name_".$app->language;
                     //echo $item->name_sp;
                     if (!property_exists($item, $field) && $item->__use_language__) {
                         $field .= "_" . $this->data->get("language")->id;
                     }
                     $label = $item->{$field};
                     //$result .= option_tag($item->$field,$item->id,($item->id==$selected));
                     $liData = array("id" => $item->id);
                     if ($item->id == $selected) {
                         $liData["class"] = "active";
                     }
                     $liContent = strtolower($options["addlinks"]) == "true" ? link_tag($item->{$field}, "#") : $item->{$field};
                     $result .= simple_tag("li", $liContent, $liData);
                 }
             }
         } else {
             $this->data->setTemporal("selected", $selected);
             $result .= $this->loop($content, $attributes);
             $this->data->clear("selected");
         }
     }
     $select = simple_tag("ul", $result, $options);
     return $select;
 }