/**
  *  test CRUD (temp: for one record) for future create data providers
  * @dataProvider objectsProvider
  */
 public function testObjectCRUD($data)
 {
     // try to add one folder to root tree
     $obj = new \CB\Objects\Object();
     // first create object
     $data['id'] = $obj->create($data);
     $this->assertTrue($data['id'] > 0, ' Error on Object create');
     // second read created object
     $obj->load($data['id']);
     $read_data = $obj->getData();
     $this->assertArraySubset($data, $read_data, false, ' readed data: ' . print_r($read_data, true));
     // third update created object
     $data['name'] = $data['name'] . ' (updated)';
     $data['data']['_title'] = $data['data']['_title'] . ' (updated)';
     $obj->update($data);
     $obj->load($data['id']);
     $read_data = $obj->getData();
     $this->assertArraySubset($data, $read_data, false, ' error on updated object data ');
     // four delete object
     $obj->delete(false);
     $obj->delete(true);
     $obj->load($data['id']);
     $read_data = $obj->getData();
     $this->assertTrue(empty($read_data['id']), 'error delete object data');
 }
Exemple #2
0
 protected function getDepth1()
 {
     $rez = array();
     $users = array();
     $office = new \CB\Objects\Object($this->office_id);
     $od = $office->load();
     if (empty($od['data']['security_group'])) {
         return $rez;
     }
     $res = DB\dbQuery('SELECT
             ug.id
             ,ug.name
             ,ug.first_name
             ,ug.last_name
             ,ug.sex
         FROM
         `users_groups_association` uga
         JOIN users_groups ug ON uga.user_id = ug.id
         WHERE uga.`group_id` = $1
         ORDER BY ug.first_name, ug.last_name, ug.name', $od['data']['security_group']);
     while ($r = $res->fetch_assoc()) {
         $name = trim($r['first_name'] . ' ' . $r['last_name']);
         if (empty($name)) {
             $name = $r['name'];
         }
         $users[$r['id']] = array('id' => $this->getId($r['id']), 'name' => $name, 'iconCls' => 'icon-user-' . $r['sex'], 'has_childs' => true);
     }
     $res->close();
     $fq = $this->fq;
     $s = new \CB\Search();
     if (@$this->requestParams['from'] == 'tree') {
         $rez['data'] = array_values($users);
         return $rez;
     }
     $sr = $s->query(array('fq' => $fq));
     return $sr;
 }
Exemple #3
0
 public static function getNodeById($id)
 {
     $o = new \CB\Objects\Object();
     return $o->load($id);
 }
Exemple #4
0
 /**
  * get search params for given request params
  * @param  array &$rp
  * @return array
  */
 protected function getSearchParams(&$rp)
 {
     $rez = array();
     // creating search object
     $so = new \CB\Objects\Object();
     if (!empty($rp['search']['template_id'])) {
         // searching from a search form
         $so->setData($rp['search']);
     } else {
         // should/will be reviewed for saved searches
         $searchId = $this->lastNode->id;
         if (!empty($rp['search']['id']) && is_numeric($rp['search']['id'])) {
             $searchId = $rp['search']['id'];
         }
         // executing a saved search
         $so->load($searchId);
     }
     $t = $so->getTemplate();
     $td = $t->getData();
     // if we have a router defined in config of the search template then try to prepare search params wit it
     // otherwise use default search method
     // if (empty($td['cfg']['router'])) {
     $rez = $t->getData()['cfg'];
     @($rez['template_id'] = $so->getData()['template_id']);
     if (empty($rez['fq'])) {
         $rez['fq'] = array();
     }
     $ld = $so->getLinearData();
     foreach ($ld as $v) {
         $condition = $this->adjustCondition($t->getField($v['name']), $v);
         if (!empty($condition)) {
             $rez['fq'][] = $condition;
         }
     }
     // } else {
     if (!empty($td['cfg']['router'])) {
         $a = explode('.', $td['cfg']['router']);
         $class = str_replace('_', '\\', $a[0]);
         $class = new $class();
         $rez = $class->{$a[1]}($rp, $rez);
     }
     return $rez;
 }
Exemple #5
0
$object = new \CB\Objects\Object();

//you can create the object by passing params to create method:
$objectId = $object->create($newObjectData);

//or by setting data an then call create
$newObjectData['pid'] = $objectId;
$newObjectData['id'] = null;
$object->setData($newObjectData);
$objectId2 = $object->create();

//loading and updating an object
$object->load($objectId);
$objectData = $object->getData();
$objectData['name'] = 'Renamed object';
$objectData['data']['_title'] = 'Renamed object';

// you can setData and then call update or just call update with data param
$object->setData($objectData);
$object->update();

// delete method will be available with next commit
// It will have a param to just mark the object as deleted in tree or completely delete object from database

// index in solr
\CB\Solr\Client::runCron();
/**/
$object = new \CB\Objects\Object(2197);
$object->load(2197);