/**
  * Given the object_data object (i.e. file_data) this function
  * updates all ObjectProperties (deleting or creating them when necessary)
  *
  * @param  $object_data
  */
 function save_properties($object_data)
 {
     $properties = array();
     for ($i = 0; $i < 200; $i++) {
         if (isset($object_data["property{$i}"]) && is_array($object_data["property{$i}"]) && (trim(array_var($object_data["property{$i}"], 'id')) != '' || trim(array_var($object_data["property{$i}"], 'name')) != '' || trim(array_var($object_data["property{$i}"], 'value')) != '')) {
             $name = array_var($object_data["property{$i}"], 'name');
             $id = array_var($object_data["property{$i}"], 'id');
             $value = array_var($object_data["property{$i}"], 'value');
             if ($id && trim($name) == '' && trim($value) == '') {
                 $property = ObjectProperties::findById($id);
                 $property->delete('id = $id');
             } else {
                 if ($id) {
                     SearchableObjects::dropContentByObjectColumn($this, 'property' . $id);
                     $property = ObjectProperties::findById($id);
                 } else {
                     $property = new ObjectProperty();
                     $property->setRelObjectId($this->getId());
                     $property->setRelObjectManager(get_class($this->manager()));
                 }
                 $property->setFromAttributes($object_data["property{$i}"]);
                 $property->save();
                 if ($this->isSearchable()) {
                     $this->addPropertyToSearchableObject($property);
                 }
             }
         } else {
             break;
         }
     }
     // for
 }
Пример #2
0
 /**
  * Update, delete and add new properties
  *
  * @access public
  * @param void
  * @return null
  */
 function update_properties()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_properties');
     $manager_class = array_var($_GET, 'manager');
     $object_id = get_id('object_id');
     $obj = Objects::findObject($object_id);
     if (!$obj instanceof ContentDataObject) {
         flash_error(lang('object dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!logged_user()->getCanManageProperties()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $new_properties = array_var($_POST, 'new_properties');
     $update_properties = array_var($_POST, 'update_properties');
     $delete_properties = array_var($_POST, 'delete_properties');
     if (is_array(array_var($_POST, 'new_properties')) || is_array(array_var($_POST, 'update_properties'))) {
         try {
             DB::beginWork();
             //add new properties
             foreach ($new_properties as $prop) {
                 $property = new ObjectProperty();
                 $property->setFromAttributes($prop);
                 $property->setRelObjectId($object_id);
                 $property->save();
             }
             foreach ($update_properties as $prop) {
                 $property = ObjectProperties::getProperty(array_var($prop, 'id'));
                 //ObjectProperties::getPropertyByName($obj, array_var($prop,'name'));
                 $property->setPropertyValue(array_var($prop, 'value'));
                 $property->save();
             }
             foreach ($delete_properties as $prop) {
                 $property = ObjectProperties::getProperty(array_var($prop, 'id'));
                 //ObjectProperties::getPropertyByName($obj, array_var($prop,'name'));
                 $prop->delete();
             }
             tpl_assign('properties', ObjectProperties::getAllPropertiesByObject($obj));
             ApplicationLogs::createLog($obj, ApplicationLogs::ACTION_EDIT);
             DB::commit();
             flash_success(lang('success add properties'));
             $this->redirectToReferer($obj->getObjectUrl());
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         //
     }
     // if
 }