Пример #1
0
 public static function findOrCreateBetween(\App\User $user, \App\User $other_user)
 {
     $user_participates = $user->privateConversations();
     $other_user_participates = $other_user->privateConversations();
     $static = new static();
     $shared_participations = collect(array_intersect($user_participates, $other_user_participates));
     return $shared_participations->isEmpty() ? $static->createBetween($user, $other_user) : $static->find($shared_participations->first());
 }
Пример #2
0
 /**
  * Find cached eloquent object
  * @param $id
  * @param $columns
  * @return Eloquent
  */
 public static function findCached($id, $columns = array('*'))
 {
     $instance = new static();
     $tableName = $instance->getTable();
     $eloquent = \Cache::remember($tableName . ':' . $id, static::$expireCache, function () use($id, $tableName, $instance, $columns) {
         return $instance->find($id, $columns);
     });
     return $eloquent;
 }
Пример #3
0
 public static function getSuppliersByBrand($id, $includeThis = false)
 {
     $instance = new static();
     $brand = $instance->find($id);
     // TODO: Make Brand able to have many Suppliers.
     $supplier = Supplier::where('id', $brand->supplied_by)->first();
     if ($includeThis === true) {
         return array($supplier, $brand);
     }
     return array($supplier);
 }
Пример #4
0
 /**
  * Helper method for creating select list options
  *
  * @param array $query
  * @return multitype:multitype:string NULL
  */
 public static function forSelection(array $query = array())
 {
     $model = new static();
     $items = $model->find($query);
     $result = array();
     foreach ($items as $doc) {
         $array = array('id' => (string) $doc['id'], 'text' => htmlspecialchars($doc['name'], ENT_QUOTES));
         $result[] = $array;
     }
     return $result;
 }
Пример #5
0
 /**
  * @param string $slug
  * @param string $locale    optional, restrict search to given locale
  * @return mixed
  */
 public static function findBySlug($slug, $locale = null)
 {
     $model = new static();
     if ($model->storeSlugLocally()) {
         return $model::findBySlug($slug);
     }
     $id = $model->findRecordIdForSlugFromCmsTable($slug, $locale);
     // if it is translated, return by entry ID instead
     if ($model->isTranslationModel()) {
         return $model->where(config('pxlcms.translatable.translation_foreign_key'), $id)->first();
     }
     return $model->find($id);
 }
 public function findAll($asMap = false)
 {
     $tokenMappings = array();
     $bao = new static();
     $bao->find(false);
     while ($bao->fetch()) {
         if ($asMap) {
             $tokenMappings[$bao->mailchimp_token] = $bao->civicrm_token;
         } else {
             $tokenMappings[] = array('id' => $bao->id, 'civicrm_token' => $bao->civicrm_token, 'mailchimp_token' => $bao->mailchimp_token);
         }
     }
     return $tokenMappings;
 }
Пример #7
0
 public function defaultData()
 {
     if (isset(static::$db_defaultdata)) {
         foreach (static::$db_defaultdata as $k => $d) {
             $obj = new static();
             if (!$obj->find($d[0])) {
                 $obj->{static::$db_idcolumn} = $d[0];
                 foreach (static::$db_columns as $ci => $c) {
                     $obj->{$c[0]} = $d[$ci + 1];
                 }
                 $obj->save();
             }
         }
     }
 }
 /**
  * Add the mailings.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  * @param array $ids
  *   Reference array contains the id.
  *
  *
  * @return CRM_Mailing_DAO_Mailing
  */
 public static function add(&$params, $ids = array())
 {
     $id = CRM_Utils_Array::value('mailing_id', $ids, CRM_Utils_Array::value('id', $params));
     if ($id) {
         CRM_Utils_Hook::pre('edit', 'Mailing', $id, $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Mailing', NULL, $params);
     }
     $mailing = new static();
     if ($id) {
         $mailing->id = $id;
         $mailing->find(TRUE);
     }
     $mailing->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
     if (!isset($params['replyto_email']) && isset($params['from_email'])) {
         $params['replyto_email'] = $params['from_email'];
     }
     $mailing->copyValues($params);
     $result = $mailing->save();
     if (!empty($ids['mailing'])) {
         CRM_Utils_Hook::post('edit', 'Mailing', $mailing->id, $mailing);
     } else {
         CRM_Utils_Hook::post('create', 'Mailing', $mailing->id, $mailing);
     }
     return $result;
 }
Пример #9
0
 /**
  * Find a DAO object for the given ID and return it.
  *
  * @param int $id
  *   Id of the DAO object being searched for.
  *
  * @return object
  *   Object of the type of the class that called this function.
  */
 public static function findById($id)
 {
     $object = new static();
     $object->id = $id;
     if (!$object->find(TRUE)) {
         throw new Exception("Unable to find a " . get_called_class() . " with id {$id}.");
     }
     return $object;
 }
Пример #10
0
 public static function getAll($opts = array())
 {
     $c = new static();
     return $c->find(array(), $opts);
 }
Пример #11
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'add_item':
             $input = $ma->getInput();
             $item_ticket = new static();
             foreach ($ids as $id) {
                 if ($item->getFromDB($id) && !empty($input['items_id'])) {
                     $input['tickets_id'] = $id;
                     $input['itemtype'] = $input['item_itemtype'];
                     if ($item_ticket->can(-1, CREATE, $input)) {
                         $ok = true;
                         if (!$item_ticket->add($input)) {
                             $ok = false;
                         }
                         if ($ok) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                     $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                 }
             }
             return;
         case 'delete_item':
             $input = $ma->getInput();
             $item_ticket = new static();
             foreach ($ids as $id) {
                 if ($item->getFromDB($id) && !empty($input['items_id'])) {
                     $item_found = $item_ticket->find("`tickets_id` = {$id} AND `itemtype` = '" . $input['item_itemtype'] . "' AND `items_id` = " . $input['items_id']);
                     if (!empty($item_found)) {
                         $item_founds_id = array_keys($item_found);
                         $input['id'] = $item_founds_id[0];
                         if ($item_ticket->can($input['id'], DELETE, $input)) {
                             $ok = true;
                             if (!$item_ticket->delete($input)) {
                                 $ok = false;
                             }
                             if ($ok) {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                             $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                         $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                     }
                 } else {
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                     $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
                 }
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Пример #12
0
 /**
  * Get groups
  *
  * @static
  * @access public
  * @param  Client    $client
  * @param  string    $query
  * @return LdapGroupProvider[]
  */
 public static function getGroups(Client $client, $query)
 {
     $self = new static(new Query($client));
     return $self->find($query);
 }
Пример #13
0
 public static function create($columns)
 {
     $instance = new static();
     foreach ($columns as $k => $v) {
         $instance->{$k} = $v;
     }
     $create = $instance->zuora()->create([$instance->castToZuora()]);
     $instance->throwExceptionOnError($create);
     return $instance->find($create->result->Id);
 }
Пример #14
0
 /**
  * Get user profile
  *
  * @static
  * @access public
  * @param  Client    $client
  * @param  string    $username
  * @return LdapUserProvider
  */
 public static function getUser(Client $client, $username)
 {
     $self = new static(new Query($client), new Group(new Query($client)));
     return $self->find($self->getLdapUserPattern($username));
 }