Beispiel #1
0
 /**
  * mark all notifications as read for given user
  * @param  int  $userId
  * @return void
  */
 public static function markAllAsRead($userId)
 {
     //validate params
     \CB\raiseErrorIf(!is_numeric($userId), 'ErroneousInputData');
     DB\dbQuery('UPDATE `' . static::getTableName() . '`
         SET `read` = 1
         WHERE user_id = $1 AND `read` = 0', $userId) or die(DB\dbQueryError());
 }
Beispiel #2
0
 /**
  * add a record
  * @param  array $p associative array with table field values
  * @return int   created id
  */
 public static function create($p)
 {
     \CB\raiseErrorIf(empty($p['name']), 'ErroneousInputData');
     return parent::create($p);
 }
Beispiel #3
0
 /**
  * get data for defined plugins to be displayed in properties panel for selected object
  * @param  array $p remote properties containing object id
  * @return ext   direct responce
  */
 public function getPluginsData($p)
 {
     $id = @$p['id'];
     $templateId = @$p['template_id'];
     $template = null;
     $templateData = null;
     $objectPlugins = null;
     $rez = array('success' => false, 'data' => array());
     if (empty($id) && empty($templateId) || !is_numeric($id) && !is_numeric($templateId)) {
         return $rez;
     }
     if (is_numeric($id)) {
         if (!$this->idExists($id)) {
             return $rez;
         }
         \CB\raiseErrorIf(!Security::canRead($id), 'Access_denied');
         $rez['menu'] = Browser\CreateMenu::getMenuForPath($id);
         /* now we'll try to detect plugins config that could be found in following places:
                1. in config of the template for the given object, named object_plugins
                2. in core config, property object_type_plugins (config definitions per available template type values: object, case, task etc)
                3. a generic config,  named default_object_plugins, could be defined in core config
            */
         $o = $this->getCachedObject($id);
         if (!empty($o)) {
             $template = $o->getTemplate();
             if (!empty($template)) {
                 $templateData = $template->getData();
             }
         }
     } else {
         $id = null;
         $templates = Templates\SingletonCollection::getInstance();
         $templateData = $templates->getTemplate($templateId)->getData();
     }
     $from = empty($p['from']) ? '' : $p['from'];
     if (!empty($from)) {
         if (isset($templateData['cfg']['object_plugins'])) {
             $op = $templateData['cfg']['object_plugins'];
             if (!empty($op[$from])) {
                 $objectPlugins = $op[$from];
             } else {
                 //check if config has only numeric keys, i.e. plugins specified directly (without a category)
                 if (!Util\isAssocArray($op)) {
                     $objectPlugins = $op;
                 } else {
                     $objectPlugins = Config::getObjectTypePluginsConfig(@$templateData['type'], $from);
                 }
             }
         }
     }
     if (empty($objectPlugins)) {
         if (!empty($templateData['cfg']['object_plugins'])) {
             $objectPlugins = $templateData['cfg']['object_plugins'];
         } else {
             $objectPlugins = Config::getObjectTypePluginsConfig($templateData['type'], $from);
         }
     }
     $rez['success'] = true;
     if (empty($objectPlugins)) {
         return $rez;
     }
     foreach ($objectPlugins as $pluginName) {
         $class = '\\CB\\Objects\\Plugins\\' . ucfirst($pluginName);
         $pClass = new $class($id);
         $prez = $pClass->getData();
         $rez['data'][$pluginName] = $prez;
     }
     //set system properties to common if SystemProperties plugin is not required
     if (empty($rez['data']['systemProperties'])) {
         $class = new Plugins\SystemProperties($id);
         $rez['common'] = $class->getData();
     }
     return $rez;
 }
Beispiel #4
0
 /**
  * validate param types
  * @param  array $p
  * @param  array $fields - default is $tableFields
  * @return void  |  throws an exception on error
  */
 protected static function validateParamTypes($p, $fields = false)
 {
     if ($fields === false) {
         $fields = static::$tableFields;
     }
     foreach ($fields as $fn => $ft) {
         $valid = true;
         if (!isset($p[$fn]) || is_null($p[$fn])) {
             continue;
         }
         switch ($ft) {
             case 'int':
             case 'smallint':
             case 'float':
                 $valid = is_numeric($p[$fn]);
                 break;
                 // case 'bool':
                 //     $valid = is_bool($p[$fn]);
                 break;
             case 'char':
                 $valid = is_string($p[$fn]) && mb_strlen($p[$fn]) < 2;
                 break;
             case 'enum':
             case 'varchar':
             case 'text':
                 $valid = is_string($p[$fn]);
                 break;
             case 'time':
             case 'timestamp':
             case 'date':
                 $dt = explode(' ', $p[$fn]);
                 $valid = sizeof($dt) < 3;
                 if ($valid) {
                     $d = explode('-', $dt[0]);
                     $valid = sizeof($dt) == 3;
                     if ($valid) {
                         $valid = is_numeric($d[0]) && is_numeric($d[1]) && is_numeric($d[2]);
                     }
                 }
                 if ($valid && !empty($dt[1])) {
                     $t = explode(':', $dt[1]);
                     $valid = sizeof($dt) < 4;
                     if ($valid) {
                         $valid = is_numeric($t[0]) && is_numeric($t[1]) && (empty($t[2]) || is_numeric($t[2]));
                     }
                 }
                 break;
         }
         \CB\raiseErrorIf(!$valid, 'ErroneousInputData');
     }
 }
Beispiel #5
0
 /**
  * update a record by username param
  * @param  array   $p array with properties
  * @return boolean
  */
 public static function updateByName($p)
 {
     \CB\raiseErrorIf(empty($p['name']), 'ErroneousInputData');
     $p['id'] = static::toId($p['name']);
     return static::update($p);
 }