예제 #1
0
 /**
  * Magic methods to handle set, get, uns
  *
  * @param string $name Value name
  * @param mixed|null $val Value
  * @throws Advertikon\Exception\InvalidArgument When value name is not a string
  * @throws Advertikon\Exception\InvalidArgument On attempt to manually set primary key
  * @return $this|mixed
  */
 public function __call($name, $val = null)
 {
     $prefix = substr($name, 0, 3);
     $key = App::underscore(substr($name, 3));
     if ($prefix === 'get') {
         $this->_checkGetKey($key);
         return isset($this->_data[$key]) ? $this->_data[$key] : null;
     } else {
         if ($prefix === 'set') {
             if ($this->_resource->getPrimaryKey() == $key) {
                 throw new InvalidArgument('Primary key can not be modified manually');
             }
             $this->_checkSetKey($key);
             $this->_data->offsetSet($key, isset($val[0]) ? $val[0] : null);
             return $this;
         } else {
             if ($prefix == 'uns') {
                 $this->_checkUnsKey($key);
                 $this->_data->offsetUnset($key);
                 return $this;
             }
         }
     }
 }
예제 #2
0
 /**
  * @see Advertikon\Resource\ResourceInterface::delete()
  */
 public function delete()
 {
     $this->_getEvent()->setParam('model', $this->_model);
     App::getModule()->app()->getEventManager()->trigger(App::PREDELETE_EVENT, $this->_getEvent());
     $affectedRows = $this->_delete();
     $this->_getEvent()->setParam('model', $this->_model);
     App::getModule()->app()->getEventManager()->trigger(App::AFTERDELETE_EVENT, $this->_getEvent());
     return $affectedRows;
 }
예제 #3
0
 /**
  * Translate text
  *
  * @param string $text Text to be translated
  * @return string
  */
 public function translate($text)
 {
     if (!is_string($text)) {
         throw new InvalidArgument(sprintf('%s: Argument must be string, %s given instead', __METHOD__, gettype($text)));
     }
     if ($this->_doTranslate && $this->_element->getOption('translate') !== false) {
         $text = App::getModule()->translate($text);
     }
     return $text;
 }
예제 #4
0
 /**
  * @see Advertikon\Resource::load()
  */
 public function _load($param)
 {
     $this->_param = $param;
     $this->_select = $this->getSelect();
     $this->_getEvent()->setParam('select', $this->_select);
     App::getModule()->app()->getEventManager()->trigger(App::GET_SELECT_EVENT, $this->_getEvent());
     if (isset($this->_model->pageable) && $this->_model->pageable) {
         $this->paginate();
     }
     $selectString = $this->_sql->buildSqlString($this->_select);
     //echo PHP_EOL . '[DB]' . $selectString . PHP_EOL;
     $result = self::$_adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
     return $result;
 }