Esempio n. 1
0
 /**
  * Retrieves all providers
  *
  * @param array filters, possible members: deleted, creator, name, provider
  *              if multiple members used then we do a logical AND with them
  * @return array array of com_meego_devprogram_device objects
  */
 public static function get_providers(array $filters)
 {
     $providers = null;
     $storage = new midgard_query_storage('com_meego_devprogram_provider');
     $q = new midgard_query_select($storage);
     if (count($filters) > 1) {
         $qc = new midgard_query_constraint_group('AND');
     }
     foreach ($filters as $filter => $value) {
         switch ($filter) {
             case 'deleted':
                 if ($value) {
                     $q->include_deleted(true);
                 }
                 break;
             case 'creator':
                 // check if the value is a real guid
                 if (mgd_is_guid($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($value));
                 }
                 break;
             case 'id':
             case 'guid':
             case 'name':
             case 'primarycontactname':
             case 'primarycontactemail':
                 $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 break;
         }
         // set the constraint
         if (isset($constraint)) {
             count($filters) > 1 ? $qc->add_constraint($constraint) : ($qc = $constraint);
         }
     }
     if (isset($qc)) {
         $q->set_constraint($qc);
     }
     $q->add_order(new midgard_query_property('metadata.created'), SORT_DESC);
     $q->execute();
     // does not seem to work
     // @bug: $q->toggle_read_only(false);
     $objects = $q->list_objects();
     if (count($objects)) {
         foreach ($objects as $object) {
             $providers[] = self::extend_provider($object);
         }
     }
     return $providers;
 }
Esempio n. 2
0
 /**
  * Retrieves programs using various filters
  *
  * @param array filters, possible members: name, creator, status
  *              if multiple members used then we do a logical AND with them
  * @return object com_meego_devprogram_program object
  */
 public static function get_programs(array $filters)
 {
     $programs = array();
     $storage = new midgard_query_storage('com_meego_devprogram_program');
     $q = new midgard_query_select($storage);
     if (count($filters) > 1) {
         $qc = new midgard_query_constraint_group('AND');
     }
     foreach ($filters as $filter => $value) {
         switch ($filter) {
             case 'deleted':
                 if ($value) {
                     $q->include_deleted(true);
                 }
                 break;
             case 'creator':
                 // check if the value is a real guid
                 if (mgd_is_guid($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($value));
                 }
                 break;
             case 'id':
             case 'name':
             case 'device':
                 $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 break;
             case 'status':
                 // current date and time
                 $now = date("Y-m-d H:i:s");
                 switch ($value) {
                     case CMD_PROGRAM_CLOSED:
                         $type = '<';
                         break;
                     case CMD_PROGRAM_OPEN:
                     default:
                         $type = '>';
                 }
                 $constraint = new midgard_query_constraint(new midgard_query_property('duedate'), $type, new midgard_query_value($now));
                 break;
             case 'daysleft':
                 // duedate < now + value
                 $now = new DateTime();
                 $limit = $now->add(new DateInterval('P' . $value . 'D'));
                 $constraint = new midgard_query_constraint(new midgard_query_property('duedate'), '<', new midgard_query_value($limit->format('Y-m-d')));
                 break;
         }
         // set the constraint
         count($filters) > 1 ? $qc->add_constraint($constraint) : ($qc = $constraint);
     }
     $q->set_constraint($qc);
     $q->add_order(new midgard_query_property('metadata.created'), SORT_DESC);
     $q->execute();
     // does not seem to work
     // @bug: $q->toggle_read_only(false);
     $objects = $q->list_objects();
     if (count($objects)) {
         foreach ($objects as $object) {
             $programs[] = self::extend_program($object);
         }
     }
     return $programs;
 }
Esempio n. 3
0
 /**
  * Loads all relations that belong to a base category
  * @param integer id of the base category
  * @return array of relation objects
  */
 public function load_relations_for_basecategory($basecategory_id = null, $includedeleted = false)
 {
     $relations = array();
     if ($basecategory_id) {
         $storage = new midgard_query_storage('com_meego_package_category_relation');
         $q = new midgard_query_select($storage);
         $qc = new midgard_query_constraint(new midgard_query_property('basecategory'), '=', new midgard_query_value($basecategory_id));
         $q->set_constraint($qc);
         if ($includedeleted) {
             $q->include_deleted(true);
         }
         $q->execute();
         $relations = $q->list_objects();
     }
     return $relations;
 }