/**
  * {@inheritdoc}
  * Create option values for product in category
  */
 public function save($cacheFlag = null)
 {
     $save = parent::save();
     /** @var xPDOQuery $q */
     $q = $this->xpdo->newQuery('msProduct', array('parent' => $this->get('category_id')));
     $q->select('id');
     if ($q->prepare() && $q->stmt->execute()) {
         $products = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
         $value = $this->get('value');
         $key = $this->getOne('Option')->get('key');
         foreach ($products as $id) {
             $po = $this->xpdo->getObject('msProductOption', array('key' => $key, 'product_id' => $id));
             // дефолтные значения применяются только к тем товарам, у которых их еще нет
             if (!$po) {
                 /* @TODO вызывать метод msOption для поддержки множественных типов  */
                 $po = $this->xpdo->newObject('msProductOption');
                 $po->set('product_id', $id);
                 $po->set('key', $key);
                 $po->set('value', $value);
                 $po->save();
             }
         }
     }
     return $save;
 }
 /**
  * Overrides xPDOObject::save to set a default created time if new.
  *
  * @param boolean $cacheFlag
  * @return boolean True if the save was successful
  */
 public function save($cacheFlag= null) {
     if ($this->_new && !$this->get('created')) {
         $this->set('created', strftime('%Y-%m-%d %H:%M:%S'));
     }
     $saved= parent :: save($cacheFlag);
     return $saved;
 }
예제 #3
0
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $new = $this->isNew();
     $class = $this->get('class');
     $save = parent::save($cacheFlag);
     if ($new) {
         $type = '';
         $ticket_id = 0;
         if ($class == 'TicketComment') {
             $type = 'vote_comment';
             /** @var TicketComment $comment */
             if ($comment = $this->xpdo->getObject('TicketComment', $this->id)) {
                 /** @var TicketThread $comment */
                 if ($thread = $comment->getOne('Thread')) {
                     $ticket_id = $thread->get('resource');
                 }
             }
         } elseif ($class == 'Ticket') {
             $type = 'vote_ticket';
             $ticket_id = $this->id;
         }
         if (!empty($type) && !empty($ticket_id)) {
             $multiplier = $this->get('value');
             /** @var TicketAuthor $profile */
             if ($profile = $this->xpdo->getObject('TicketAuthor', $this->get('owner'))) {
                 $profile->addAction($type, $this->id, $ticket_id, $multiplier);
             }
         }
     }
     return $save;
 }
예제 #4
0
 public function prepareRow(xPDOObject $object)
 {
     $object->set('encrypted', 0);
     $object->set('values', $this->modx->toJSON($object->decrypt()));
     $object->save();
     $ff = $object->toArray();
     return $ff;
 }
 public function save($cacheFlag = null)
 {
     $saved = parent::save($cacheFlag);
     if ($saved) {
         $this->clearCache();
     }
     return $saved;
 }
 /**
  * Overrides xPDOObject::save to clear lexicon cache on saving.
  *
  * {@inheritdoc}
  */
 public function save($cacheFlag = null)
 {
     $saved = parent::save($cacheFlag);
     if ($saved && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
         $this->clearCache();
     }
     return $saved;
 }
 public function save($cacheFlag = null)
 {
     $saved = parent::save();
     if ($saved && !$this->getOption(xPDO::OPT_SETUP)) {
         $this->xpdo->call('modNamespace', 'clearCache', array(&$this->xpdo));
     }
     return $saved;
 }
예제 #8
0
 public function prepareRow(xPDOObject $object)
 {
     $object->set('encrypted', 1);
     $values = $object->get('values');
     $object->set('values', $object->encrypt($values));
     $object->save();
     $ff = $object->toArray();
     return $ff;
 }
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $time = time();
     $this->set('createdon', $time);
     $this->set('year', date('Y', $time));
     $this->set('month', date('m', $time));
     $this->set('day', date('d', $time));
     return parent::save($cacheFlag);
 }
예제 #10
0
 /** {@inheritdoc} */
 public function save($cacheFlag = null)
 {
     if ($this->isNew()) {
         $ip = $this->xpdo->request->getClientIp();
         $this->set('registration', time());
         $this->set('lastactivity', time());
         $this->set('type', $this->xpdo->userprofile2->getProfileTypeDefault());
         $this->set('ip', $ip['ip']);
     }
     return parent::save($cacheFlag);
 }
예제 #11
0
 /**
  * Overrides xPDOObject::save to fire modX-specific events.
  * 
  * {@inheritDoc}
  */
 public function save($cacheFlag = null)
 {
     $isNew = $this->isNew();
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnPluginEventBeforeSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'pluginEvent' => &$this, 'cacheFlag' => $cacheFlag));
     }
     $saved = parent::save($cacheFlag);
     if ($saved && $this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnPluginEventSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'pluginEvent' => &$this, 'cacheFlag' => $cacheFlag));
     }
     return $saved;
 }
예제 #12
0
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $new = $this->isNew();
     $parent = parent::save($cacheFlag);
     if ($new && ($uid = $this->get('uid'))) {
         /** @var TicketAuthor $profile */
         if ($profile = $this->xpdo->getObject('TicketAuthor', $uid)) {
             $profile->addAction('view', $this->get('parent'), $this->get('parent'));
         }
     }
     return $parent;
 }
예제 #13
0
 /**
  * {@inheritDoc}
  * @return mixed
  */
 public function process()
 {
     /* Run the beforeSet method before setting the fields, and allow stoppage */
     $canSave = $this->beforeSet();
     if ($canSave !== true) {
         return $this->failure($canSave);
     }
     $this->newObject->fromArray($this->object->toArray());
     $name = $this->getNewName();
     $this->setNewName($name);
     if ($this->alreadyExists($name)) {
         $this->addFieldError($this->nameField, $this->modx->lexicon($this->objectType . '_err_ae', array('name' => $name)));
     }
     $canSave = $this->beforeSave();
     if ($canSave !== true) {
         return $this->failure($canSave);
     }
     /* save new chunk */
     if ($this->newObject->save() === false) {
         $this->modx->error->checkValidation($this->newObject);
         return $this->failure($this->modx->lexicon($this->objectType . '_err_duplicate'));
     }
     $this->afterSave();
     $this->logManagerAction();
     return $this->cleanup();
 }
 /**
  * Custom save that respects access policies.
  *
  * {@inheritdoc}
  */
 public function save($cacheFlag = null)
 {
     $saved = false;
     if (!$this->checkPolicy('save')) {
         $this->xpdo->error->failure($this->xpdo->lexicon('permission_denied'));
     }
     $saved = parent::save($cacheFlag);
     return $saved;
 }
예제 #15
0
 /**
  * Prepare the row for iteration
  * @param xPDOObject $object
  * @return array
  */
 public function prepareRow(xPDOObject $object)
 {
     $objectArray = $object->toArray();
     $value = $objectArray['value'];
     $value = str_replace(',', '||', $value);
     $values = array_map('trim', @explode('||', $value));
     if (!empty($values)) {
         $valuesArray = array();
         foreach ($values as $value) {
             if (empty($value)) {
                 continue;
             }
             $valuesArray[] = $value;
             $tag = $this->modx->getObject('smarttagTags', array('tag:LIKE' => $value));
             if (!$tag) {
                 $tag = $this->modx->newObject('smarttagTags');
                 $tag->set('tag', $value);
                 if ($tag->save() === false) {
                     $this->modx->log(modX::LOG_LEVEL_ERROR, __LINE__ . ': Error on saving new tag data: ' . $value);
                     continue;
                 }
             }
             $params = array('tag_id' => $tag->getPrimaryKey(), 'tmplvar_id' => $objectArray['tmplvarid'], 'resource_id' => $objectArray['contentid']);
             $smarttagTagresource = $this->modx->getObject('smarttagTagresources', $params);
             if (!$smarttagTagresource) {
                 $smarttagTagresource = $this->modx->newObject('smarttagTagresources');
                 $smarttagTagresource->fromArray($params, NULL, TRUE, TRUE);
                 if ($smarttagTagresource->save() === false) {
                     $this->modx->log(modX::LOG_LEVEL_ERROR, __LINE__ . ': Error on saving new tag resource data: ' . print_r($params, 1));
                     continue;
                 }
                 $this->_count++;
             }
         }
         $valuesArray = array_unique($valuesArray);
         if (!empty($valuesArray)) {
             $newValue = @implode('||', $valuesArray);
             if ($objectArray['value'] !== $newValue) {
                 $object->set('value', $newValue);
                 if ($object->save()) {
                     $objectArray['value'] = $newValue;
                 }
             }
         }
     }
     return $objectArray;
 }
예제 #16
0
 /**
  * Abstract the saving of the object out to allow for transient and non-persistent object updating in derivative
  * classes
  * @return boolean
  */
 public function saveObject()
 {
     return $this->newObject->save();
 }
예제 #17
0
 /**
  * @param bool $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     $isNew = $this->isNew();
     $this->logFields = $this->xpdo->fromJSON($this->xpdo->getOption('mlmsystem_log_fields_' . __CLASS__, null, '{}'));
     if ($isNew) {
         $this->set('createdon', time());
     } else {
         $this->set('updatedon', time());
     }
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('MlmSystemOnClientBeforeSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'client' => &$this, 'cacheFlag' => $cacheFlag));
     }
     /* log fields  */
     foreach ($this->logFields as $field => $type) {
         if (!array_key_exists($field, $this->_fieldMeta)) {
             continue;
         }
         if (!$this->isDirty($field)) {
             continue;
         }
         if ($value = $this->get($field)) {
             $this->log($field, $value, $type);
         }
     }
     $saved = parent::save($cacheFlag);
     if ($saved && $this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('MlmSystemOnClientSave', array('mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD, 'client' => &$this, 'cacheFlag' => $cacheFlag));
     }
     return $saved;
 }
예제 #18
0
 /**
  * @param null $cacheFlag
  *
  * @return bool
  */
 public function save($cacheFlag = null)
 {
     if ($this->isNew()) {
         $this->set('createdon', time());
     }
     return parent::save($cacheFlag);
 }