/** * Set updated * * @param null|int|string|\DateTime|\Zork\Stdlib\DateTime $updated * @return \Customize\Model\Rule\Structure */ public function setUpdated($updated) { $this->updated = DateTime::create($updated, true); return $this; }
/** * Find updated times * * @param array|int $rootParagraphIds * @param bool|null $global * @return DateTime[] */ public function findUpdated($rootParagraphIds, $global = null) { if ($rootParagraphIds instanceof Traversable) { $rootParagraphIds = ArrayUtils::iteratorToArray($rootParagraphIds); } else { if (!is_array($rootParagraphIds)) { $rootParagraphIds = (array) $rootParagraphIds; } } if (null === $global && in_array(null, $rootParagraphIds)) { $global = true; } if (empty($rootParagraphIds)) { return array(); } $rootParagraphIds = array_filter($rootParagraphIds); if ($global) { if (empty($rootParagraphIds)) { $where = array(new Predicate\IsNull('rootParagraphId')); } else { $where = array(new Predicate\PredicateSet(array(new Predicate\IsNull('rootParagraphId'), new Predicate\In('rootParagraphId', $rootParagraphIds)), Predicate\PredicateSet::COMBINED_BY_OR)); } } else { $where = array('rootParagraphId' => $rootParagraphIds); } $select = $this->sql()->select()->columns(array('rootParagraphId', 'updated'))->where($where)->order(array(new Expression('COALESCE( ?, 0 ) ASC', array('rootParagraphId'), array(Expression::TYPE_IDENTIFIER)))); /* @var $result \Zend\Db\Adapter\Driver\ResultInterface */ $result = $this->sql()->prepareStatementForSqlObject($select)->execute(); $affected = $result->getAffectedRows(); if ($affected < 1) { return array(); } $updated = array(); foreach ($result as $row) { $updated[$row['rootParagraphId']] = DateTime::create($row['updated']); } return $updated; }