Пример #1
0
 /**
  * Create an item
  * new item: __construct($config, $data)
  *
  * @param array конфиг
  * @param array record
  * @param bool verified = true if data load from DB, false = create new object
  */
 function __construct(IAbs_Collection $container, $config = false, $data = false, $verified = false)
 {
     $inerface_check = 'IAbs_Collection';
     if (!$container instanceof $inerface_check) {
         throw new collection_exception('Bad constructor syntax', tf_exception::CRITICAL);
     }
     $this->db = $container->get_db();
     $this->set_container($container);
     $this->set_key($container->get_key());
     //
     // dummy object
     //
     if (!$config) {
         $this->is_dummy = true;
         $this->construct_dummy_after();
         return;
     }
     $this->config = $config instanceof collection_params ? $config : new collection_params($config);
     // get this from parent collection
     $this->set_working_fields($container->get_working_fields());
     $this->behaviors = new model_behaviors();
     $this->create_behaviors();
     $this->construct_before($data);
     // проверенная загрузка
     if ($verified) {
         $this->_is_new = false;
         if (!empty($data)) {
             $this->filter_data($data);
             $this->set_data($data);
             // from alloc()
             if (!empty($config['allocated'])) {
                 $this->_is_new = true;
                 //from alloc
                 $this->_is_allocated = true;
             }
             if ($this->get_key()) {
                 if (!$this->_is_new && !isset($data[$this->get_key()])) {
                     throw new Collection_Exception('Create collection_item without ID [' . $this->get_key() . '], but verified flag specified');
                 }
                 $this->set_id($data[$this->get_key()]);
             }
         }
     } else {
         if ($data !== false) {
             // newb! (создается новый)
             $this->create($data);
             $this->_is_new = false;
         }
     }
     $this->make_urls();
     $this->construct_after();
     if ($deps = $this->with_deps()) {
         $this->load_secondary($deps);
     }
 }
Пример #2
0
 /**
     Create an item
     new item: __construct($config, $data)
     
     @param array конфиг
     @param array record
     @param bool verified = true if data load from DB, false = create new object
 */
 function __construct(IAbs_Collection $container, $config = false, $data = false, $verified = false)
 {
     $inerface_check = 'IAbs_Collection';
     if (!$container instanceof $inerface_check) {
         throw new collection_exception('Bad constructor syntax', tf_exception::CRITICAL);
     }
     $this->db = $container->get_db();
     $this->set_container($container);
     // dummy object
     if (!$config) {
         return;
     }
     $this->config = $config;
     // check for extra fields
     /*
     if (defined('IN_EDITOR')) {
       $this->valid_fields_check();
     }
     */
     // проверенная загрузка
     if ($verified) {
         $this->_is_new = false;
         if (!empty($data)) {
             $this->filter_data($data);
             $this->data = $data;
             if (!isset($data['id'])) {
                 throw new collection_exception('Create collection_item without ID, but verified flag specified');
             }
             $this->id = $data['id'];
         }
     } else {
         if ($data !== false) {
             // newb! (создается новый)
             $this->create($data);
         }
     }
     // load extra fields
     $this->load_extra_fields();
     $this->make_urls();
     $this->on_create();
 }