コード例 #1
0
ファイル: Fixed.php プロジェクト: nurikk/EvilRocketFramework
 public function __construct($type, $id = null, $data = null)
 {
     $this->_type = $type;
     $this->_fixed = new Zend_Db_Table(Evil_DB::scope2table($type));
     $info = $this->_fixed->info();
     $this->_fixedschema = $info['cols'];
     $this->_lastQuery = $this->_fixed->select()->from($this->_fixed);
 }
コード例 #2
0
ファイル: Hybrid.php プロジェクト: nurikk/EvilRocketFramework
 public function __construct($type)
 {
     $this->_type = $type;
     $this->_fixed = new Zend_Db_Table(Evil_DB::scope2table($type, '-fixed'));
     $this->_fluid = new Zend_Db_Table(Evil_DB::scope2table($type, '-fluid'));
     $info = $this->_fixed->info();
     $this->_fixedschema = $info['cols'];
 }
コード例 #3
0
ファイル: Fluid.php プロジェクト: nurikk/EvilRocketFramework
 public function __construct($type, $id = null)
 {
     $this->type = $type;
     $this->_fluid = new Zend_Db_Table(Evil_DB::scope2table($type));
     if (null !== $id) {
         $this->load($id);
     }
     return true;
 }
コード例 #4
0
ファイル: Form.php プロジェクト: nurikk/EvilRocketFramework
 /**
  * @description create a table object, if table exists
  * @static
  * @param string $name
  * @return bool|Zend_Db_Table
  * @author Se#
  * @version 0.0.1
  */
 public static function getTable($name)
 {
     if (!is_string($name)) {
         return false;
     }
     $tables = Zend_Registry::get('db')->listTables();
     $name = Evil_DB::scope2table($name);
     $table = false;
     if (in_array($name, $tables)) {
         $table = new Zend_Db_Table($name);
     }
     return $table;
 }
コード例 #5
0
ファイル: FixedM.php プロジェクト: nurikk/EvilRocketFramework
 public function __construct($type, $id = null)
 {
     $this->_type = $type;
     $this->_fixed = new Zend_Db_Table(Evil_DB::scope2table($type));
     $this->_select = new Zend_Db_Table_Select($this->_fixed);
     $info = $this->_fixed->info();
     $this->_info = $info;
     $this->_fixedschema = $info['cols'];
     if (null !== $id) {
         $this->load($id);
     }
     return true;
 }
コード例 #6
0
 public function __construct($type, $id = null, $data = null)
 {
     $this->type = $type;
     $this->_fixed = new Zend_Db_Table(Evil_DB::scope2table($type, '-fixed'));
     $this->_fluid = new Zend_Db_Table(Evil_DB::scope2table($type, '-fluid'));
     $info = $this->_fixed->info();
     $this->_info = $info;
     $this->_fixedschema = $info['cols'];
     if ($data !== null) {
         $this->_data = $data;
         $this->_loaded = true;
     } else {
         if (null !== $id) {
             $this->load($id);
         }
     }
     return true;
 }
コード例 #7
0
ファイル: Plugin.php プロジェクト: nurikk/EvilRocketFramework
 /**
  * @description add Evil/Controller/ directory to the Front Controller
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  * @author Se#
  * @version 0.0.2
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $controllerName = $request->getControllerName();
     // check if there is asked controller in base controller directory
     if (!is_file(APPLICATION_PATH . '/controllers/' . ucfirst($controllerName) . 'Controller.php')) {
         // check if there is a controller in the Evil/Controller/ directory
         if (!is_file(__DIR__ . '/' . ucfirst($controllerName) . 'Controller.php')) {
             $tables = Zend_Registry::get('db')->listTables();
             if (in_array(Evil_DB::scope2table($controllerName), $tables)) {
                 $path = APPLICATION_PATH . '/configs/evil/controller/restricted.json';
                 $restricted = is_file($path) ? json_decode(file_get_contents($path), true) : array();
                 if (in_array($controllerName, $restricted)) {
                     return $request;
                 }
                 $this->_newClass($controllerName);
             } else {
                 return $request;
             }
         }
         Zend_Controller_Front::getInstance()->addControllerDirectory(__DIR__);
     }
 }
コード例 #8
0
ファイル: Factor.php プロジェクト: nurikk/EvilRocketFramework
 /**
  * @description inject factor fields into form
  * @param array $formConfig
  * @param object $table
  * @param string $action
  * @param object $config
  * @param array $params
  * @return
  * @author Se#
  * @version 0.0.1
  */
 protected function _getFormConfig()
 {
     $config = self::$_info['config'];
     $params = self::$_info['params'];
     $factors = $this->_getFactorsList($config);
     $formConfig = array('class' => 'factor_form', 'elements' => array('do' => array('type' => 'hidden', 'options' => array('value' => 'factor'))));
     $formConfig['elements']['factorobjectId'] = array('type' => 'hidden', 'options' => array('value' => $params['id']));
     $formConfig['elements']['factorobjectTable'] = array('type' => 'hidden', 'options' => array('value' => Evil_DB::scope2table($params['controller'])));
     $formConfig['elements']['factortype'] = array('type' => 'select', 'options' => array('label' => 'Choose factor type', 'multiOptions' => $factors));
     $formConfig['elements']['factorcontent'] = array('type' => 'textarea', 'options' => array('rows' => '5', 'cols' => 40));
     $userTable = new Zend_Db_Table(Evil_DB::scope2table('user'));
     $user = $userTable->fetchRow('id="' . Zend_Registry::get('userid') . '"');
     if (!$user) {
         $userName = '******';
     } else {
         $user = $user->toArray();
         $userName = isset($user['nickname']) ? $user['nickname'] : 'User';
     }
     $formConfig['elements']['factorauthor'] = array('type' => 'text', 'options' => array('label' => 'Please, introduce yourself', 'value' => $userName, 'readOnly' => true));
     $formConfig['elements']['submit'] = array('type' => 'submit', 'options' => array('label' => 'Add'));
     return $formConfig;
 }
コード例 #9
0
 protected function _getUserName()
 {
     $controller = self::$_info['controller'];
     $name = 'Guest';
     if (-1 != Zend_Registry::get('userid')) {
         if (isset($controller->selfConfig['comments']['author']['table'])) {
             $table = $controller->selfConfig['comments']['author']['table'];
             $field = $controller->selfConfig['comments']['author']['idField'];
             $nameField = $controller->selfConfig['comments']['author']['nameField'];
         } else {
             $table = 'user';
             $field = 'id';
             $nameField = 'name';
         }
         $table = new Zend_Db_Table(Evil_DB::scope2table($table));
         $user = $table->fetchRow($table->select()->where($field . '=?', Zend_Registry::get('userid')));
         if ($user) {
             $user = $user->toArray();
             $name = isset($user[$nameField]) ? $user[$nameField] : 'Missed "' . $nameField . '" ';
         }
     }
     return $name;
 }
コード例 #10
0
ファイル: Vote.php プロジェクト: nurikk/EvilRocketFramework
 /**
  * @description save vote into a DB and forwards to the next action
  * @param array $forward where to go after action is over
  * @return void
  * @author Se#
  * @version 0.0.1
  */
 public function _actionDefault()
 {
     // define if there are required fields
     if (!isset(self::$_info['params']['objectId']) || !isset(self::$_info['params']['objectTable'])) {
         self::$_info['controller']->_redirect('/');
     }
     $params = self::$_info['params'];
     // for the more comfort
     $session = new Zend_Session_Namespace('evil-votes');
     // get session
     $voteTable = new Zend_Db_Table(Evil_DB::scope2table('vote'));
     // get table; TODO: get name from a config
     // If there are votes and count for the current object, than get last mark from it
     if (isset($session->votes) && isset($session->votes[$params['objectId'] . $params['objectTable']])) {
         $params['mark'] += $session->votes[$params['objectId'] . $params['objectTable']];
     } else {
         // otherwise get last mark from a DB
         $vote = $voteTable->fetchRow($voteTable->select()->where('objectId=?', $params['objectId'])->where('objectTable=?', $params['objectTable'])->order('ctime DESC'));
         $params['mark'] += $vote ? is_object($vote) ? $vote->mark : $vote['mark'] : 0;
     }
     $params['ctime'] = time();
     // set creation time
     // insert data, clean off system params such as controller, action, etc
     $voteTable->insert($this->_cleanParams($params));
     if (isset($session->votes)) {
         // Save current mark into session
         $session->votes[$params['objectId'] . $params['objectTable']] = $params['mark'];
     }
     // define where should forward
     $forward = isset(self::$_info['controller']->selfConfig['vote']['forward']) ? self::$_info['controller']->selfConfig['vote']['forward'] : array('list', self::$_info['controllerName'], null, array());
     // forward
     call_user_func_array(array(self::$_info['controller'], '_forward'), $forward);
     //self::$_info['controller']->_forward($forward[0], $forward[1], $forward[2], $forward[3]);
 }
コード例 #11
0
ファイル: Array.php プロジェクト: nurikk/EvilRocketFramework
 /**
  * @description make a new array($field => whole cell| data[$perField]);
  * Example:
  * $users = Array(
  *  0 => array('id' => 2, 'login' => 'user1'),
  *  1 => array('id' => 3, 'login' => 'userN')
  * )
  * $result = Evil_Array::byField($users, null, 'id', 'login');
  *
  * $result :
  * array(
  *  2 => 'user1',
  *  3 => 'userN'
  * )
  * 
  * @static
  * @param array|string $dataOrName array for operating or a table name (will fetch all)
  * @param object|null $db
  * @param string $field
  * @param bool $perField
  * @return array
  * @author Se#
  * @version 0.0.1
  */
 public static function byField($dataOrName = array(), $db = null, $field = 'id', $perField = false)
 {
     $db = $db ? $db : Zend_Registry::get('db');
     if (is_string($dataOrName)) {
         // name
         $data = $db->fetchAll($db->select()->from(Evil_DB::scope2table($dataOrName)));
     } else {
         $data = $dataOrName;
     }
     $result = array();
     $count = count($data);
     for ($i = 0; $i < $count; $i++) {
         $id = isset($data[$i][$field]) ? $data[$i][$field] : 0;
         $result[$id] = $perField && isset($data[$i][$perField]) ? $data[$i][$perField] : $data[$i];
     }
     return $result;
 }
コード例 #12
0
 /**
  * @description prepare table
  * @param object $config
  * @param string $action
  * @param string $controllerName
  * @return Zend_Db_Table
  * @author Se#
  * @version 0.0.2
  */
 public function table()
 {
     $config = self::getStatic('config');
     $action = self::getStatic('params', 'action');
     $controllerName = self::getStatic('controllerName');
     // check if there is optional table name
     $table = isset($config->{$action}->tableName) ? $config->{$action}->tableName : $controllerName;
     $table = new Zend_Db_Table(Evil_DB::scope2table($table));
     if (method_exists($this, '_changeTable')) {
         $table = $this->_changeTable($table);
     }
     return $table;
 }
コード例 #13
0
 /**
  * @description place data into a DB
  * @param array $result
  * @return bool
  * @author Se#
  * @version 0.0.1
  */
 protected function _db($result)
 {
     if (isset($this->_cfg['dispatch']['db']) && is_array($this->_cfg['dispatch']['db'])) {
         $result = $this->_clear($result);
         if (isset($this->_cfg['dispatch']['db']['tableName'])) {
             $table = new Zend_Db_Table(Evil_DB::scope2table($this->_cfg['dispatch']['db']['tableName']));
             $table->insert($result);
         } else {
             return false;
         }
     }
     return true;
 }