Exemplo n.º 1
0
 /**
  * save an object
  * @param array $p{ object properties
  *       @type int $id id of the object to be updated or null for crating a new object
  *       @type int $pid parent id
  *       @type int $template_id
  *       @type int $oid owner id
  *       @type array $data {
  *             <field_id | field_name> => <scalar value> | array( //single field
  *                 'value' => 'field value'
  *                 ,'info' => 'field info'
  *                 ,'childs' => array(
  *                     <field_id | field_name> =>
  *                     ...
  *                 )
  *             )
  *             ,<field_id | field_name> => <scalar value> | array( // multiplied field
  *                 <scalar value> | array(
  *                     'value' => 'field value'
  *                     ,'info' => 'field info'
  *                     ,'childs' => array(
  *
  *                     )
  *                 )
  *                 ,<scalar value> | array(
  *                     'value' => 'field value'
  *                     ,'info' => 'field info'
  *                     ,'childs' => array(
  *
  *                     )
  *                 )
  *             )
  *       }
  * }
  * @return json responce
  */
 public function save($p)
 {
     /*check params validity */
     $params_validation = $this->validateInputParamsForCreate($p);
     if ($params_validation !== true) {
         throw new \Exception("Params validation failed: " . $params_validation, 1);
     }
     /* end of check params validity */
     $_SESSION['user'] = array('id' => $p['oid']);
     $data = array();
     $data['id'] = empty($p['id']) ? null : $p['id'];
     $data['pid'] = $p['pid'];
     $data['template_id'] = $p['template_id'];
     $data['oid'] = $p['oid'];
     //define template_id for internal use in this class
     $this->template_id = $p['template_id'];
     /* transforming grid data */
     if (empty($p['data'])) {
         if (!empty($p['tmplData'])) {
             $p['data'] =& $p['tmplData'];
         } else {
             $p['data'] = array();
         }
     }
     $data['data'] = $p['data'];
     $objects = new \CB\Objects();
     $rez = $objects->save(array('data' => $data));
     return $rez;
 }
 /**
  *  create an object with given data
  * @return int object id
  */
 public function createObject($data)
 {
     $class = new \CB\Objects();
     $data = $class->create($data);
     return $data['data']['id'];
 }