public function save($cacheFlag = null)
 {
     if ($isNew = $this->isNew()) {
         /*if(!$this->get('createdon')){
               $this->set('createdon', time());
           }
           
           if(!$this->get('createdby')){
               $this->set('createdby', $this->xpdo->user->id ? $this->xpdo->user->id : null);
           }*/
         $this->set('ip', $this->getUserIP());
     }
     if (!$this->get('parent')) {
         $this->set('parent', null);
     }
     /*
             Не делаем так, потому что иначе при обновлении дочерних комментов
             у нас все родительские комменты будут тоже обновленными
             else{
                 if(!$this->get('editedon')){
                     $this->set('editedon', time());
                 }
             }*/
     $rt = parent::save($cacheFlag);
     /*
         If saved and it`s was new comment, recalculate total comments
     */
     if ($rt && $isNew) {
         $this->recalculateParentComments(1);
     }
     return $rt;
 }
 public function save($cacheFlag = null)
 {
     if (empty($this->key)) {
         $this->key = md5($this->id . time() . $this->dir_name);
     }
     return parent::save($cacheFlag);
 }
Example #3
1
 public function save($cacheFlag = null)
 {
     if ($this->alias == '') {
         $this->set('alias', $this->generateUniqueAlias($this->name));
     }
     return parent::save($cacheFlag);
 }
 /**
  * Overrides xPDOObject::remove to fire modX-specific events
  *
  * {@inheritDoc}
  */
 public function remove(array $ancestors = array())
 {
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnUserGroupBeforeRemove', array('usergroup' => &$this, 'ancestors' => $ancestors));
     }
     $removed = parent::remove($ancestors);
     // delete ACLs for this group
     $targets = explode(',', $this->xpdo->getOption('principal_targets', null, 'modAccessContext,modAccessResourceGroup,modAccessCategory'));
     array_walk($targets, 'trim');
     foreach ($targets as $target) {
         $fields = $this->xpdo->getFields($target);
         if (array_key_exists('principal_class', $fields) && array_key_exists('principal', $fields)) {
             $tablename = $this->xpdo->getTableName($target);
             $principal_class_field = $this->xpdo->escape('principal_class');
             $principal_field = $this->xpdo->escape('principal');
             if (!empty($tablename)) {
                 $this->xpdo->query("DELETE FROM {$tablename} WHERE {$principal_class_field} = 'modUserGroup' AND {$principal_field} = {$this->_fields['id']}");
             }
         }
     }
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnUserGroupRemove', array('usergroup' => &$this, 'ancestors' => $ancestors));
     }
     return $removed;
 }
 /**
  * Override getOne to get the appropriate Principal class.
  *
  * @param $alias
  * @param null $criteria
  * @param bool $cacheFlag
  * @return null|xPDOObject
  */
 public function &getOne($alias, $criteria = null, $cacheFlag = true)
 {
     $object = null;
     if ($alias === 'Principal') {
         if ($fkdef = $this->getFKDefinition($alias)) {
             $k = $fkdef['local'];
             $fk = $fkdef['foreign'];
             if (isset($this->_relatedObjects[$alias])) {
                 if (is_object($this->_relatedObjects[$alias])) {
                     $object =& $this->_relatedObjects[$alias];
                     return $object;
                 }
             }
             if ($criteria === null) {
                 $criteria = array($fk => $this->get($k));
             }
             $fkdef['class'] = $this->get('principal_class');
             if ($object = $this->xpdo->getObject($fkdef['class'], $criteria, $cacheFlag)) {
                 $this->_relatedObjects[$alias] = $object;
             }
         }
     } else {
         $object = parent::getOne($alias, $criteria, $cacheFlag);
     }
     return $object;
 }
 public function save($cacheFlag = NULL)
 {
     if (!$this->get('topicid') && empty($this->_relatedObjects['Topic']) or !$this->get('blogid') && empty($this->_relatedObjects['Blog'])) {
         return false;
     }
     return parent::save($cacheFlag);
 }
Example #7
0
 /**
  * Make sure we clean up names
  */
 public function set($k, $v = null, $vType = '')
 {
     if ($k == 'name') {
         $v = strip_tags(trim(preg_replace('/\\s+/', ' ', $v)));
     }
     return parent::set($k, $v, $vType);
 }
 public function save($cacheFlag = null)
 {
     if ($this->isNew()) {
         $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
     }
     return parent::save($cacheFlag);
 }
 public function save($cacheFlag = null)
 {
     $preventsave = $this->get('preventsave');
     $published = $this->get('published');
     $this->event = $this->getOne('Event');
     //handle enddate - enddate can't be lower than startdate
     $enddate = $this->get('enddate');
     $startdate = $this->get('startdate');
     if ($enddate <= $startdate) {
         $this->set('enddate', $startdate);
     }
     //handle allday
     $this->handleAllday();
     $active = true;
     if (empty($published)) {
         $active = false;
     }
     if ($active) {
         if (!$this->handleDouble()) {
             return true;
         }
         if (!$this->handleDoubleInAssignedCats()) {
             return true;
         }
     }
     if (!$preventsave) {
         return parent::save($cacheFlag);
     } else {
         return true;
     }
 }
 /**
  * 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)
 {
     if (!$this->get('resourceid')) {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Resource ID is null");
         return false;
     }
     return parent::save($cacheFlag);
 }
Example #12
0
 /** {@inheritdoc} */
 public function remove(array $ancestors = array())
 {
     $id = $this->get('id');
     $table = $this->xpdo->getTableName('msDeliveryMember');
     $sql = "DELETE FROM {$table} WHERE `delivery_id` = '{$id}';";
     $this->xpdo->exec($sql);
     return parent::remove();
 }
 public function remove(array $ancestors = array())
 {
     $removed = parent::remove($ancestors);
     if ($removed && !$this->getOption(xPDO::OPT_SETUP)) {
         $this->xpdo->call('modExtensionPackage', 'clearCache', array(&$this->xpdo));
     }
     return $removed;
 }
Example #14
0
 /**
  * Overrides xPDOObject::save to set the createdon date.
  *
  * {@inheritdoc}
  */
 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;
 }
 public function get($k, $format = null, $formatTemplate = null)
 {
     if ($k == 'badge') {
         $v = $this->getBadge();
     } else {
         $v = parent::get($k, $format, $formatTemplate);
     }
     return $v;
 }
 public function save($cacheFlag = null)
 {
     if (!$this->Source) {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Attempt to save object without MediaSource: ' . print_r($this->toArray('', true), 1));
         return false;
     }
     $this->path = $this->Source->getPath($this->path);
     return parent::save($cacheFlag);
 }
Example #17
0
 public function save($cacheFlag = null)
 {
     if (!$this->checkDuplicate()) {
         $out = parent::save($cacheFlag);
     } else {
         $this->xpdo->log(xPDO::LOG_LEVEL_INFO, '[ThumbImages] Duplicate records for ' . $this->get('image') . ' with config ' . $this->config);
         $out = false;
     }
     return $out;
 }
 function set($k, $v = null, $vType = '')
 {
     switch ($k) {
         // Protect changing class_key
         case 'class_key':
             $v = $this->get($k);
             break;
     }
     return parent::set($k, $v, $vType);
 }
Example #19
0
 public function save($cacheFlag = null)
 {
     $saved = parent::save($cacheFlag);
     if ($saved) {
         if ($this->xpdo->getCacheManager()) {
             $this->xpdo->cacheManager->delete('gallery/item/list/');
         }
     }
     return $saved;
 }
 public function save($cacheFlag = null)
 {
     $update = $this->isDirty('active');
     $save = parent::save($cacheFlag);
     /** @var msdCouponGroup $group */
     if ($update && ($group = $this->getOne('Group'))) {
         $group->updateCounters();
     }
     return $save;
 }
Example #21
0
 /**
  * Overrides xPDOObject::remove to fire modX-specific events
  *
  * {@inheritDoc}
  */
 public function remove(array $ancestors = array())
 {
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnUserGroupBeforeRemove', array('usergroup' => &$this, 'ancestors' => $ancestors));
     }
     $removed = parent::remove($ancestors);
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('OnUserGroupRemove', array('usergroup' => &$this, 'ancestors' => $ancestors));
     }
     return $removed;
 }
Example #22
0
 /**
  * @param bool $cacheFlag
  * @return bool
  */
 public function save($cacheFlag = false)
 {
     $isNew = $this->isNew();
     if ($isNew) {
         $this->set('createdon', date('Y-m-d H:i:s'));
     } else {
         $this->set('updatedon', date('Y-m-d H:i:s'));
     }
     $saved = parent::save($cacheFlag);
     return $saved;
 }
Example #23
0
 /**
  * @param array $ancestors
  * @return bool
  */
 public function remove(array $ancestors = array())
 {
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('MlmSystemOnLogBeforeRemove', array('log' => &$this, 'ancestors' => $ancestors));
     }
     $removed = parent::remove($ancestors);
     if ($this->xpdo instanceof modX) {
         $this->xpdo->invokeEvent('MlmSystemOnLogRemove', array('log' => &$this, 'ancestors' => $ancestors));
     }
     return $removed;
 }
 /**
  * Overrides the xPDOObject::remove method to remove the physical file for
  * the attachment
  *
  * @param array $ancestors
  * @return boolean
  */
 public function remove(array $ancestors = array())
 {
     $filename = $this->get('filename');
     if (!empty($filename)) {
         $filename = $this->getPath();
         if (!@unlink($filename)) {
             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, '[Discuss] An error occurred while trying to remove the attachment file at: ' . $filename);
         }
     }
     return parent::remove($ancestors);
 }
 public function toArray($keyPrefix = '', $rawValues = false, $excludeLazy = false, $includeRelated = false)
 {
     $array = parent::toArray($keyPrefix, $rawValues, $excludeLazy);
     if (!empty($this->xpdo->lexicon) && $this->xpdo->lexicon instanceof modLexicon) {
         if ($this->get('lexicon') != 'core:dashboards') {
             $this->xpdo->lexicon->load($this->get('lexicon'));
         }
         $array['name_trans'] = $this->xpdo->lexicon->exists($this->get('name')) ? $this->xpdo->lexicon($this->get('name')) : $this->get('name');
         $array['description_trans'] = $this->xpdo->lexicon->exists($this->get('description')) ? $this->xpdo->lexicon($this->get('description')) : $this->get('description');
     }
     return $array;
 }
Example #26
0
 /** 
  * Make sure the relations actually exist.
  */
 public function save($cacheFlag = null)
 {
     if (!($Asset = $this->xpdo->getObject('Asset', $this->get('asset_id')))) {
         $this->xpdo->log(\modX::LOG_LEVEL_ERROR, 'Invalid Asset ID: ' . $this->get('asset_id'), '', __CLASS__);
         throw new \Exception('Invalid Asset ID specified for PageAsset');
     }
     if (!($Page = $this->xpdo->getObject('modResource', $this->get('page_id')))) {
         $this->xpdo->log(\modX::LOG_LEVEL_ERROR, 'Invalid Page ID: ' . $this->get('page_id'), '', __CLASS__);
         throw new \Exception('Invalid Page ID specified for PageAsset');
     }
     return parent::save($cacheFlag);
 }
 public function save($cacheFlag = null)
 {
     if (!$this->User) {
         $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "[- " . __CLASS__ . " -]. User required");
         return false;
     }
     if (!$this->NoticeType) {
         $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "[- " . __CLASS__ . " -]. NoticeType required");
         return false;
     }
     return parent::save($cacheFlag);
 }
Example #28
0
 /** {inheritDoc} */
 public function save($cacheFlag = null)
 {
     if ($this->get('email_to') == '') {
         return false;
     }
     $hash = sha1(serialize(array('subscriber_id' => $this->subscriber_id, 'newsletter_id' => $this->newsletter_id, 'email_to' => $this->email_to, 'email_subject' => $this->email_subject, 'email_body' => $this->email_body, 'email_from' => $this->email_from, 'email_from_name' => $this->email_from_name, 'email_reply' => $this->email_reply)));
     if (!$this->xpdo->getCount('sxQueue', array('hash' => $hash))) {
         $this->set('hash', $hash);
         return parent::save($cacheFlag);
     } else {
         return true;
     }
 }
 /**
  * Overrides xPDOObject::save to clear lexicon cache on saving.
  *
  * {@inheritdoc}
  */
 public function save($cacheFlag = null)
 {
     if ($this->_new) {
         if (!$this->get('createdon')) {
             $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
         }
     }
     $saved = parent::save($cacheFlag);
     if ($saved && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
         $this->clearCache();
     }
     return $saved;
 }
Example #30
0
 public function save($cacheFlag = null)
 {
     /* if the start datetime is empty, should default to right now */
     if (empty($this->start)) {
         $this->start = date("Y-m-d H:i:s");
     }
     /* if the end datetime is empty, shoud default to datetime of its parent event */
     if (empty($this->end)) {
         $event = $this->getOne('Event');
         $this->end = $event->date;
     }
     return parent::save($cacheFlag);
 }