Inheritance: extends CommonTreeDropdown
示例#1
0
 /**
  * send a message to specified fluentd.
  *
  * @todo use HTTP1.1 protocol and persistent socket.
  * @param string $tag
  * @param array  $data
  */
 public function post2(Entity $entity)
 {
     $packed = json_encode($entity->getData());
     $request = sprintf('http://%s:%d/%s?json=%s', $this->host, $this->port, $entity->getTag(), urlencode($packed));
     $ret = file_get_contents($request);
     return $ret !== false;
 }
示例#2
0
 function GetKids()
 {
     $entity = new Entity();
     $query = "SELECT * FROM #__categories WHERE parent = ? ORDER BY ordering";
     $objects = $entity->Collection($query, $this->id, __CLASS__);
     return $objects;
 }
示例#3
0
文件: menu.php 项目: boolive/basic
 /**
  * Преобразование ветки объектов в структуру из массивов для вывода в шаблоне
  * @param array $items Масив объектов - пунктов меню
  * @param Entity $active Активный пункт меню
  * @param bool $sub_active Признак, есть или нет активные подчиненные?
  * @return array
  */
 protected function itemsToArray($items, $active, &$sub_active = false)
 {
     $list = array();
     $have_active = false;
     foreach ($items as $item) {
         $children = $item['sub'];
         $item = $item['object'];
         $real = $item->linked();
         $info = array('title' => $item->title->value(), 'icon' => false, 'url' => Request::url($real->uri()), 'active' => $active && $active->eq($real) ? 1 : 0);
         // Иконка
         //            $icon = $item->icon->isExist() ? $item->icon : ($real->icon->isExist()? $real->icon : null);
         //            if ($icon && !$icon->isDraft() && !$icon->isHidden()){
         //                $info['icon'] = $icon->resize(0,30,Image::FIT_OUTSIDE_LEFT_TOP)->file();
         //            }
         // Если заголовок не определен
         if (empty($info['title'])) {
             $info['title'] = $real->title->value();
             if (empty($info['title'])) {
                 $info['title'] = $real->name();
             }
         }
         if ($children) {
             $info['children'] = $this->itemsToArray($children, $active, $sub_active);
             if (!$info['active'] && $sub_active) {
                 $info['active'] = 2;
             }
         }
         $have_active = $have_active || $info['active'];
         $list[] = $info;
     }
     $sub_active = $have_active;
     return $list;
 }
示例#4
0
 public function testInit()
 {
     $entity = new Entity();
     $entity->name = 'myname';
     $entity->loginname = 'test';
     $entity->save();
 }
示例#5
0
function can_upload($session)
{
    if ($session['authenticator']) {
        $auth = $session['authenticator'];
        $reason_session =& get_reason_session();
        $username = $reason_session->get("username");
        if (isset($_REQUEST['user_id']) && !empty($_REQUEST['user_id'])) {
            $username = $reason_session->get('username');
            $param_cleanup_rules = array('user_id' => array('function' => 'turn_into_int', 'extra_args' => array('zero_to_null' => 'true')));
            $cleanRequest = array_merge($_REQUEST, carl_clean_vars($_REQUEST, $param_cleanup_rules));
            $nametag = $cleanRequest['user_id'];
            $id = get_user_id($username);
            if (reason_user_has_privs($id, 'pose_as_other_user')) {
                $user = new Entity($nametag);
                $username = $user->get_value("name");
            }
        }
        if ($auth['file']) {
            require_once $auth['file'];
        }
        $args = array_merge(array($username), $auth['arguments']);
        if (!call_user_func_array($auth['callback'], $args)) {
            return false;
        }
    }
    return true;
}
 public function testInitJoinTableSelfReferencingInsertingData()
 {
     $e = new Entity();
     $e->name = "Entity test";
     $this->assertTrue($e->Entity[0] instanceof Entity);
     $this->assertTrue($e->Entity[1] instanceof Entity);
     $this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_TCLEAN);
     $this->assertEqual($e->Entity[1]->state(), Doctrine_Record::STATE_TCLEAN);
     $e->Entity[0]->name = 'Friend 1';
     $e->Entity[1]->name = 'Friend 2';
     $e->Entity[0]->Entity[0]->name = 'Friend 1 1';
     $e->Entity[0]->Entity[1]->name = 'Friend 1 2';
     $e->Entity[1]->Entity[0]->name = 'Friend 2 1';
     $e->Entity[1]->Entity[1]->name = 'Friend 2 2';
     $this->assertEqual($e->Entity[0]->name, 'Friend 1');
     $this->assertEqual($e->Entity[1]->name, 'Friend 2');
     $this->assertEqual($e->Entity[0]->Entity[0]->name, 'Friend 1 1');
     $this->assertEqual($e->Entity[0]->Entity[1]->name, 'Friend 1 2');
     $this->assertEqual($e->Entity[1]->Entity[0]->name, 'Friend 2 1');
     $this->assertEqual($e->Entity[1]->Entity[1]->name, 'Friend 2 2');
     $this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_TDIRTY);
     $this->assertEqual($e->Entity[1]->state(), Doctrine_Record::STATE_TDIRTY);
     $count = count($this->conn);
     $e->save();
     $this->assertEqual($count + 13, $this->conn->count());
 }
示例#7
0
 public function save(Entity $entity)
 {
     $users = $this->db->get_all('users');
     foreach ($users['data'] as $key => $value) {
         $this->db->insert($this->table, array('msg' => $entity->getMessage(), 'is_read' => 0, 'user_id' => $value['id'], 'sender_id' => $this->user_id, 'recepient_id' => $value['id'], 'date_added' => $entity->getDate()));
     }
 }
示例#8
0
 private function generateNoSuchModelException(Entity $entity)
 {
     $className = "NoSuch{$entity->getName()}Exception";
     $content = "<?php\nclass {$className} extends Exception {\n\n}\n?>";
     $destination = "src/exceptions/{$className}.php";
     FileUtil::storeFileContents($destination, $content);
 }
示例#9
0
 public function onEntitySave(Entity $entity)
 {
     //save to entity name only if doesn't exist
     if (!$entity->rawGet('name')) {
         $entity->setEntityField('name', $this->getFullName(false));
     }
 }
 /**
  * Compares two entities A and B. If A contains a foreign key referring to B, then A > B. So when sorting a list of
  * entities this way, the entities will be sorted in creation order. (In this case B < A, because B must be created
  * before A.)
  *
  * @param Entity $entityA
  * @param Entity $entityB
  * @return int compare
  */
 public static function compareFkDependency(Entity $entityA, Entity $entityB)
 {
     if ($entityA == $entityB) {
         return 0;
     }
     // Check if A has a foreign key that (directly or indirectly) refers to B.
     $levelAtoB = $entityA->contaisFkReferringTo($entityB);
     // Check if B has a foreign key that (directly or indirectly) refers to A.
     $levelBtoA = $entityB->contaisFkReferringTo($entityA);
     if ($levelAtoB < 0) {
         // A does not contain a reference to B.
         if ($levelBtoA < 0) {
             // B does not contain a reference to A either, so A and B are not related.
             return 0;
         } else {
             // B contains a reference to A, so B < A.
             return -1;
         }
     } else {
         // A contains a reference to B...
         if ($levelBtoA < 0) {
             // ...and B does not contain a reference to A, so A < B.
             return 1;
         } else {
             // ...and B contains a reference to A too. The strongest wins!
             return $levelAtoB < $levelBtoA ? 1 : -1;
         }
     }
 }
示例#11
0
 public static function process(Entity $entity, $maxDepth = 10)
 {
     if ($maxDepth <= 0) {
         $mapper = $entity->_getMapper();
         $primaryKey = $mapper->getPrimaryKey($mapper->getTable(get_class($entity)));
         return isset($primaryKey) && isset($entity->{$primaryKey}) ? $entity->{$primaryKey} : null;
     }
     $data = [];
     foreach ($entity->getData() as $name => $value) {
         if (is_array($value)) {
             $items = [];
             foreach ($value as $item) {
                 $items[] = self::process($item, $maxDepth - 1);
             }
             $value = $items;
         } elseif (is_object($value) && !is_null($value)) {
             if ($value instanceof \DateTime) {
                 $value = $value->format('Y-m-d H:i:s');
             } elseif ($value instanceof Entity) {
                 $value = self::process($value, $maxDepth - 1);
             }
         }
         $data[$name] = $value;
     }
     return $data;
 }
示例#12
0
 public function processRow($row)
 {
     $arr = str_getcsv($row);
     $ticker = $arr[0];
     $name = $arr[1];
     $name = str_replace('&#39;', "'", $name);
     if ($name == 'Name') {
         return false;
     }
     $cap = $arr[3];
     if ($cap < $this->min_market_cap) {
         $this->too_small_ct++;
         return false;
     } else {
         $corp = Doctrine::getTable('PublicCompany')->findOneByTicker($ticker);
         if ($corp) {
             $this->existing_ct++;
             return false;
         } else {
             $corp = new Entity();
             $corp->addExtension('Org');
             $corp->addExtension('Business');
             $corp->addExtension('PublicCompany');
             $corp->ticker = $ticker;
             $corp->name = $name;
             $corp->save();
             $this->printDebug("New company added: " . $name);
             $this->added_ct++;
         }
     }
 }
示例#13
0
 /**
  * Swaps field values of two objects
  *
  * @param Entity $object1
  * @param Entity $object2
  * @param string $field name of the field to be swapped
  */
 public function swap(Entity $object1, Entity $object2, $field)
 {
     $old_field = $object1[$field];
     $object1[$field] = $object2[$field];
     $object2[$field] = $old_field;
     $object1->store();
     $object2->store();
 }
示例#14
0
 /**
  * @param \PHPSC\Conference\Infra\Persistence\Entity $obj
  */
 public function update(Entity $obj)
 {
     if ($obj->getId() == 0) {
         throw new EntityDoesNotExistsException('Não é possível atualizar uma entidade que ainda não foi adicionada');
     }
     $this->getEntityManager()->persist($obj);
     $this->getEntityManager()->flush();
 }
示例#15
0
 private function generateIndexes(Entity $entity)
 {
     $indexes = array("\tPRIMARY KEY (`{$entity->getPrimaryKey()->getName()}`)");
     foreach ($entity->getFinders() as $finder) {
         $indexes[] = "\t" . $finder->getIndexDefinition();
     }
     return $indexes;
 }
示例#16
0
   protected function setUp() {
      global $DB;
      
      $DB->connect();

      // Store Max(id) for each glpi tables
      $result = $DB->list_tables();
      while ($data=$DB->fetch_row($result)) {
         $query = "SELECT MAX(`id`) AS MAXID
                   FROM `".$data[0]."`";
         foreach ($DB->request($query) as $row) {
            $this->tables[$data[0]] = (empty($row['MAXID']) ? 0 : $row['MAXID']);
         }
      }
      $DB->free_result($result);

      $tab  = array();
      $auth = new Auth();
      // First session
      $auth->Login('glpi', 'glpi') ;

      // Create entity tree
      $entity = new Entity();
      $tab['entity'][0] = $entity->add(array('name' => 'PHP Unit root',
                                             'entities_id' => 0));

      if (!$tab['entity'][0]                                   // Crash detection
          || !FieldExists('glpi_profiles','notification')   // Schema detection
          || countElementsInTable('glpi_rules')!=6) {    // Old rules

         if (!$tab['entity'][0]) {
            echo "Couldn't run test (previous run not cleaned)\n";
         } else {
            echo "Schema need to be updated\n";
         }
         echo "Loading a fresh empty database:";
         $DB->runFile(GLPI_ROOT ."/install/mysql/glpi-0.84-empty.sql");
         die(" done\nTry again\n");
      }

      $tab['entity'][1] = $entity->add(array('name'        => 'PHP Unit Child 1',
                                             'entities_id' => $tab['entity'][0]));

      $tab['entity'][2] = $entity->add(array('name'        => 'PHP Unit Child 2',
                                             'entities_id' => $tab['entity'][0]));

      $tab['entity'][3] = $entity->add(array('name'        => 'PHP Unit Child 2.1',
                                             'entities_id' => $tab['entity'][2]));

      $tab['entity'][4] = $entity->add(array('name'        => 'PHP Unit Child 2.2',
                                             'entities_id' => $tab['entity'][2]));

      // New session with all the entities
      $auth->Login('glpi', 'glpi') or die("Login glpi/glpi invalid !\n");

      // Shared this with all tests
      $this->sharedFixture = $tab;
   }
 public function save(Entity $entity)
 {
     $dataInput = array('image' => $entity->getImage(), 'tours_id' => $entity->getToursId());
     if ($entity->getId() > 0) {
         $this->update($entity->getId(), $dataInput);
     } else {
         $this->create($dataInput);
     }
 }
示例#18
0
文件: Alias.php 项目: ignaszak/cms
 /**
  *
  * @param string $string
  * @return string
  */
 public function getAlias(string $string) : string
 {
     if (empty($this->entity->getAlias())) {
         $alias = $this->createAliasFromString($string);
         return $this->renameAliasIfExistsInDB($alias);
     } else {
         return $this->entity->getAlias();
     }
 }
示例#19
0
 public function save(Entity $entity)
 {
     $item = array('title' => $entity->getTitle(), 'url' => $entity->getUrl());
     if ($entity->getId() > 0) {
         $this->update($item, array('id' => $entity->getId()));
     } else {
         $this->add($item);
     }
 }
 protected function save(Entity $entity)
 {
     if ($entity->isNew()) {
         $this->add($entity);
     } else {
         $this->update($entity);
     }
     return $this->pdo->lastInsertId();
 }
 /**
  * @param Entity $entity
  * @return int
  */
 protected function postImpl(Entity $entity)
 {
     /*
      * example ouputs:
      *   2012-02-26T01:26:20+0900        debug.test      {"hello":"world"}
      */
     $format = "%s\t%s\t%s\n";
     return $this->write(sprintf($format, date(\DateTime::ISO8601, $entity->getTime()), $entity->getTag(), json_encode($entity->getData())));
 }
示例#22
0
 static function Retrieve($user_id, $cfg_name)
 {
     if (!$user_id || !$cfg_name) {
         return null;
     }
     $entity = new Entity();
     $query = "SELECT * FROM #__messages_cfg WHERE user_id = ? AND cfg_name = ?";
     return $entity->GetFirstResult($query, array($user_id, $cfg_name), __CLASS__);
 }
 public function save(Entity $entity)
 {
     $dataInput = array('blog_post_id' => $entity->getBlogPostId(), 'image' => $entity->getImage());
     if ($entity->getId() > 0) {
         $this->update($entity->getId(), $dataInput);
     } else {
         $this->create($dataInput);
     }
 }
示例#24
0
 public function addEntity(Entity $entity)
 {
     $rel = $entity->getRel();
     if (empty($rel)) {
         throw new \InvalidArgumentException("Sub-entities must contain a rel");
     }
     $this->entities[] = $entity;
     return $this;
 }
 public function save(Entity $entity)
 {
     $dataInput = array('name' => $entity->getName(), 'description' => $entity->getDescription());
     if ($entity->getId() > 0) {
         $this->update($entity->getId(), $dataInput);
     } else {
         $this->create($dataInput);
     }
 }
示例#26
0
 /**
  * Saves an idno entity to the database, returning the _id
  * field on success.
  *
  * @param Entity $object
  */
 function saveObject($object)
 {
     if ($object instanceof \Idno\Common\Entity) {
         if ($collection = $object->getCollection()) {
             $array = $object->saveToArray();
             return $this->saveRecord($collection, $array);
         }
     }
     return false;
 }
 public function prepareData()
 {
     parent::prepareData();
     //we create a test entity that is not a user and not a group
     $entity = new Entity();
     $entity->name='Other Entity';
     $entity->type = 2; 
     $entity->save();
     $this->otherEntity = $entity;
 }
 public function generate(Entity $entity)
 {
     $className = "{$entity->getName()}Service";
     $destination = "src/impl/service/{$className}.php";
     if (FileUtil::fileExists($destination)) {
         return;
     }
     $content = "<?php\nclass {$className} extends {$className}Base {\n\n}\n?>";
     FileUtil::storeFileContents($destination, $content);
 }
 public function getByEntityId($entityId)
 {
     global $wpdb;
     $objectEntity = new Entity();
     if (is_int($entityId)) {
         $entityId = strval($entityId);
     }
     $entity = $objectEntity->getByEntityId($entityId);
     return $entity;
 }
 public function testRelationSaving2()
 {
     $e = new Entity();
     $e->name = 'test';
     $e->save();
     $nr = new Phonenumber();
     $nr->phonenumber = '1234556';
     $nr->save();
     $nr->Entity = $e;
 }