예제 #1
0
 public function render()
 {
     if (is_object($this->params)) {
         $this->params = \System\Std\Object::getProperties($this->params);
     }
     if (is_array($this->params)) {
         $href = $this->attributes['href'];
         foreach ($this->params as $param => $val) {
             $href = \System\Std\String::set($href)->replace('@' . $param, $val);
         }
         $this->attributes['href'] = $href;
     }
     return $this->control->append('<a ')->append($this->renderAttributes())->append('>')->append($this->title)->append('</a>')->toString();
 }
예제 #2
0
 private function toXml($collection, $rootNode)
 {
     foreach ($collection as $key => $value) {
         $key = is_numeric($key) ? 'item' : $key;
         if (is_array($value)) {
             $subNode = $rootNode->addChild($key);
             $this->toXml($value, $subNode);
         } elseif (is_object($value)) {
             $segments = explode('\\', get_class($value));
             $subNode = $rootNode->addChild(array_pop($segments));
             $this->toXml(\System\Std\Object::getProperties($value), $subNode);
         } else {
             $rootNode->addChild($key, htmlentities($value));
         }
     }
     return $rootNode;
 }
예제 #3
0
 public function saveChanges()
 {
     $log = array();
     foreach ($this->dbSets as $set) {
         $meta = $set->getMeta();
         $entities = $set->getEntities();
         foreach ($entities as $entityContext) {
             $entity = $entityContext->getEntity();
             $properties = Object::getProperties($entity);
             foreach ($properties as $property => $value) {
                 if (is_object($value)) {
                     $parentEntityHash = spl_object_hash($value);
                     if ($this->persistedEntities->hasKey($parentEntityHash)) {
                         $parentEntityContext = $this->persistedEntities->get($parentEntityHash);
                         $parentMeta = $this->dbSets[$parentEntityContext->getName()]->getMeta();
                         $properties[$property] = Object::getPropertyValue($value, $parentMeta->getKey()->getKeyName());
                     }
                 }
                 if ($value instanceof \System\Std\Date) {
                     $properties[$property] = $value->toString('yyyy-MM-dd HH:mm:ss');
                 }
                 $columnAttributes = $meta->getColumnAttributes($property);
                 foreach ($columnAttributes as $attribute) {
                     if ($attribute instanceof \System\Data\Entity\Attributes\ConstraintAttribute) {
                         $attribute->setColumnName($property);
                         $attribute->setValue($value);
                         if (!$attribute->isValid()) {
                             throw new Attributes\ConstraintAttributeException($attribute->getErrorMessage());
                         }
                     }
                     if ($attribute instanceof \System\Data\Entity\Attributes\DefaultValue) {
                         if (is_null($value)) {
                             $properties[$property] = $attribute->getDefaultValue();
                             Object::setPropertyValue($entity, $property, $attribute->getDefaultValue());
                         }
                     }
                 }
             }
             switch ($entityContext->getState()) {
                 case EntityContext::PERSIST:
                     $result = $this->conn->insert($meta->getTable()->getTableName(), $properties);
                     $log[] = $result;
                     if ($result) {
                         Object::setPropertyValue($entity, $meta->getKey()->getKeyName(), $this->conn->getInsertId($meta->getKey()->getKeyName()));
                         $entityContext->setState(EntityContext::PERSISTED);
                         $this->persistedEntities->add($entityContext->getHashCode(), $entityContext);
                     }
                     break;
                 case EntityContext::PERSISTED:
                     $updateParams = array($meta->getKey()->getKeyName() => $properties[$meta->getKey()->getKeyName()]);
                     $log[] = $this->conn->update($meta->getTable()->getTableName(), $properties, $updateParams);
                     break;
                 case EntityContext::DELETE:
                     $updateParams = array($meta->getKey()->getKeyName() => $properties[$meta->getKey()->getKeyName()]);
                     $log[] = $this->conn->delete($meta->getTable()->getTableName(), $properties, $updateParams);
                     $this->persistedEntities->removeAt($entityContext->getHashCode());
                     $set->detach($entity);
                     break;
             }
         }
     }
     return array_sum($log);
 }
예제 #4
0
 public function max($field)
 {
     $this->sortBy($field);
     $count = $this->count() - 1;
     if (isset($this->collection[$count])) {
         $item = \System\Std\Object::getProperties($this->collection[$count]);
         return $item[$field];
     }
 }