Пример #1
0
 public function __construct($id_or_elementsTypes = null, $storage = null, &$specialDataStorage = null)
 {
     $this->construct($id_or_elementsTypes, $specialDataStorage);
     //Asings the storage element for the SimplOnelement. (a global one : or a particular one)
     if (!$specialDataStorage) {
         $this->dataStorage = Main::dataStorage();
     } else {
         $this->dataStorage =& $specialDataStorage;
     }
     //On heirs put here the asignation of SimplOndata and attributes
     if (is_array($id_or_elementsTypes)) {
         if (array_values($id_or_elementsTypes) === $id_or_elementsTypes) {
             $this->elementsTypes = new DArray('', 'vclsR', $id_or_elementsTypes);
         } else {
             $this->fillFromArray($id_or_elementsTypes);
         }
     } else {
         if (isset($id_or_elementsTypes)) {
             $id = $id_or_elementsTypes;
             $this->dataStorage->ensureElementStorage($this);
             $this->fillFromDSById($id);
         }
     }
     //checking if there is already a dataStorage and storage for this element
     //if there is a storage and an ID it fills the element with the proper info.
     if (!$this->storage()) {
         $storages = array();
         foreach ($this->elementsTypes() as $elementType) {
             $dummy_class = new $elementType();
             $storages[$elementType] = $dummy_class->storage();
         }
         $this->storage($storages);
     }
     $this->getFields();
     $this->viewAction = new Datas\ViewAction('', array('View'));
     // @todo: make it possible to create a new Search using an HTML form
     $this->createAction = new Datas\CreateAction('', array('Create'));
     $this->updateAction = new Datas\UpdateAction('', array('Update'));
     $this->deleteAction = new Datas\DeleteAction('', array('Delete'));
     // Tells the SimplOndata whose thier "container" in case any of it has context dependent info or functions.
     $this->assignAsDatasParent();
     $this->assignDatasName();
 }
Пример #2
0
 /**
  * - Calls user defined constructor.
  * - Adds default Element's actions.
  * - Validates DataStorages.
  * - Fills its Datas' values if possible (requires a valid ID or array of values).
  * - Fills some of its Datas' meta-datas (parent, names).
  * @param mixed $id_or_array ID of the Element or array of Element's Datas values.  
  * @param DataStorage $specialDataStorage DataStorage to use in uncommon cases.
  */
 public function __construct($id_or_array = null, $storage = null, $specialDataStorage = null)
 {
     $this->sonMessage = new \SimplOn\Datas\Message();
     $this->construct($id_or_array, $storage, $specialDataStorage);
     //On heirs put here the asignation of SimplOndata and attributes
     if ($storage) {
         $this->storage($storage);
     } else {
         $this->storage(strtr($this->getClass(), '\\', '_'));
     }
     //Assings the storage element for the SimplOnelement. (a global one : or a particular one)
     if (!$specialDataStorage) {
         $this->dataStorage = Main::dataStorage();
     } else {
         $this->dataStorage =& $specialDataStorage;
     }
     if (!$this->quickDelete) {
         $this->quickDelete = Main::$QUICK_DELETE;
     }
     if (!isset($this->viewAction)) {
         $this->viewAction = new Datas\ViewAction('', array('View'));
     }
     if (!isset($this->createAction)) {
         $this->createAction = new Datas\CreateAction('', array('Create'));
     }
     if (!isset($this->updateAction)) {
         $this->updateAction = new Datas\UpdateAction('', array('Update'));
     }
     if (!isset($this->deleteAction)) {
         $this->deleteAction = new Datas\DeleteAction('', array('Delete'));
     }
     //if( !isset($this->selectAction) )$this->selectAction = new Datas\SelectAction('', array('Select'));
     //$this->multiSelectAction = new Datas\DeleteAction('', array('Select'));
     //Load the attributes on the fly
     $this->addOnTheFlyAttributes();
     $this->assignDatasName();
     //user_error($this->{$this->field_id()}());
     // Tells the SimplOndata whose thier "container" in case any of it has context dependent info or functions.
     $this->assignAsDatasParent();
     //checking if there is already a dataStorage and storage for this element
     $this->dataStorage->ensureElementStorage($this);
     if (is_array($id_or_array)) {
         $this->fillFromArray($id_or_array);
     } else {
         if ($id_or_array) {
             //if there is a storage and an ID it fills the element with the proper info.
             $this->fillFromDSById($id_or_array);
         }
     }
 }